Skip to content

Commit 189ecf0

Browse files
committed
Fix bug with CData elements #79
1 parent 32ccdca commit 189ecf0

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<groupId>com.github.miachm.sods</groupId>
77
<artifactId>SODS</artifactId>
88
<packaging>jar</packaging>
9-
<version>1.6.0</version>
9+
<version>1.6.3</version>
1010

1111
<name>Simple ODS library</name>
1212
<description>A library for load/save ODS files in java.</description>

resources/features/bugs/cellContent.feature

+6
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,9 @@ Feature: Bugs related to invalid cell value content in SODS
2323
When the client creates a Range with 1,1,1,1
2424
Then the formula of the range is "SUM(Operations!C:C)"
2525

26+
Scenario: Data tags returns a null value
27+
When load a spreadsheet from the resource "emptyCell"
28+
When get the first sheet
29+
Then the cell values are:
30+
| Test 1 |
31+
| A |

src/com/github/miachm/sods/OdsReader.java

-1
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,6 @@ private void readCellText(XmlReaderInstance cellReader, Range range) {
505505
} else {
506506
s.append("\n");
507507
}
508-
509508
// Add content of any contained text:span tags
510509
XmlReaderInstance spanElement = textElement.nextElement("text:s",
511510
XmlReaderInstance.CHARACTERS);

src/com/github/miachm/sods/XmlReaderInstanceEventImpl.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import javax.xml.stream.XMLStreamReader;
66
import java.util.HashMap;
77
import java.util.Map;
8+
import javax.xml.stream.XMLStreamConstants;
89

910
class XmlReaderInstanceEventImpl implements XmlReaderInstance {
1011
private XMLStreamReader reader;
@@ -24,7 +25,7 @@ class XmlReaderInstanceEventImpl implements XmlReaderInstance {
2425
String value = reader.getAttributeValue(i);
2526
atributes.put(name, value);
2627
}
27-
else if (reader.isCharacters()) {
28+
else if (isCharacters(reader)) {
2829
characters = reader.getText();
2930
end = true;
3031
}
@@ -58,7 +59,7 @@ else if (reader.isEndElement()) {
5859
return null;
5960
}
6061
}
61-
else if (reader.isCharacters()) {
62+
else if (isCharacters(reader)) {
6263
if (contains(names, CHARACTERS))
6364
return new XmlReaderInstanceEventImpl(reader, CHARACTERS);
6465
}
@@ -85,7 +86,11 @@ public String getContent()
8586
public String getTag() {
8687
return tag;
8788
}
88-
89+
90+
private boolean isCharacters(XMLStreamReader reader) {
91+
return reader.isCharacters() || reader.getEventType() == XMLStreamConstants.CDATA;
92+
}
93+
8994
private String qNameToString(QName qName)
9095
{
9196
return qName.getPrefix() + ":" + qName.getLocalPart();

tests/steps/SpreadsheetCucumber.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public void the_cell_values_are(DataTable dataTable) throws Throwable {
246246
Object[][] items = World.sheet.getDataRange().getValues();
247247

248248
for (int i = 0; i < table.size(); i++) {
249-
for (int j = 0; j < table.size(); j++) {
249+
for (int j = 0; j < table.get(i).size(); j++) {
250250
String value = table.get(i).get(j);
251251
if (value.equals(""))
252252
value = null;

0 commit comments

Comments
 (0)