Skip to content

Commit

Permalink
Fix #204
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Aug 18, 2016
1 parent 23ab583 commit 79a4b57
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
5 changes: 5 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Project: jackson-dataformat-xml

No changes since 2.7.

2.7.7 (not yet released)

#204: FromXMLParser nextTextValue() incorrect for attributes
(reported by frederikz@github)

2.7.6 (23-Jul-2016)
2.7.5 (11-Jun-2016)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,6 @@ public String nextTextValue() throws IOException
_parsingContext = _parsingContext.getParent();
_namesToWrap = _parsingContext.getNamesToWrap();
break;

case XmlTokenStream.XML_ATTRIBUTE_NAME:
// If there was a chance of leaf node, no more...
if (_mayBeLeaf) {
Expand All @@ -667,9 +666,8 @@ public String nextTextValue() throws IOException
}
break;
case XmlTokenStream.XML_ATTRIBUTE_VALUE:
_currText = _xmlTokens.getText();
_currToken = JsonToken.VALUE_STRING;
break;
return (_currText = _xmlTokens.getText());
case XmlTokenStream.XML_TEXT:
_currText = _xmlTokens.getText();
if (_mayBeLeaf) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.fasterxml.jackson.dataformat.xml.stream;

import java.io.*;

import com.fasterxml.jackson.core.*;

import com.fasterxml.jackson.dataformat.xml.XmlFactory;
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
import com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser;

public class XmlParserNextXxxTest extends XmlTestBase
{
protected JsonFactory _jsonFactory;
protected XmlFactory _xmlFactory;

// let's actually reuse XmlMapper to make things bit faster
@Override
public void setUp() throws Exception {
super.setUp();
_xmlFactory = new XmlFactory();
}

/*
/**********************************************************
/* Unit tests
/**********************************************************
*/

// [dataformat-xml#204]
public void testXmlAttributesWithNextTextValue() throws Exception
{
final String XML = "<data max=\"7\" offset=\"9\"/>";

FromXmlParser xp = (FromXmlParser) _xmlFactory.createParser(new StringReader(XML));

// First: verify handling without forcing array handling:
assertToken(JsonToken.START_OBJECT, xp.nextToken()); // <data>
assertToken(JsonToken.FIELD_NAME, xp.nextToken()); // <max>
assertEquals("max", xp.getCurrentName());

assertEquals("7", xp.nextTextValue());

assertToken(JsonToken.FIELD_NAME, xp.nextToken()); // <offset>
assertEquals("offset", xp.getCurrentName());

assertEquals("offset", xp.getText());

assertEquals("9", xp.nextTextValue());

assertEquals("9", xp.getText());

assertToken(JsonToken.END_OBJECT, xp.nextToken()); // </data>
xp.close();
}
}

0 comments on commit 79a4b57

Please sign in to comment.