Skip to content

Commit 273fb14

Browse files
committed
Improved attribute parser to handle values with equal signs
1 parent 215d2fd commit 273fb14

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/main/java/com/github/underscore/Xml.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1527,7 +1527,7 @@ static Map<String, String> parseAttributes(final String source) {
15271527
boolean quoteFound = false;
15281528
boolean equalFound = false;
15291529
for (int index = 0; index < source.length(); index += 1) {
1530-
if (source.charAt(index) == '=') {
1530+
if (source.charAt(index) == '=' && !quoteFound) {
15311531
equalFound = !equalFound;
15321532
continue;
15331533
}

src/test/java/com/github/underscore/LodashTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,19 @@ void xmpToJson4() {
10281028
+ "</z:catalog>"));
10291029
}
10301030

1031+
@Test
1032+
void xmpToJson5() {
1033+
assertEquals("{\n" +
1034+
" \"Comment\": {\n" +
1035+
" \"-stringValue\": \"============================\",\n" +
1036+
" \"-self-closing\": \"true\"\n" +
1037+
" },\n" +
1038+
" \"#omit-xml-declaration\": \"yes\"\n" +
1039+
"}",
1040+
U.xmlToJson(
1041+
"<Comment stringValue=\"============================\"/>"));
1042+
}
1043+
10311044
@Test
10321045
void xmlToJsonMinimum() {
10331046
assertEquals(

src/test/java/com/github/underscore/StringTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,9 +2358,11 @@ void parseAttributes() {
23582358
"{version=1.0}",
23592359
Xml.parseAttributes(" version = \"1.0\" encoding= \"UTF-8 ").toString());
23602360
assertEquals(
2361-
"{}", Xml.parseAttributes(" version = \"1.0 encoding= \"UTF-8\" ").toString());
2361+
"{version=1.0 encoding= }",
2362+
Xml.parseAttributes(" version = \"1.0 encoding= \"UTF-8\" ").toString());
23622363
assertEquals(
2363-
"{}", Xml.parseAttributes(" version = 1.0\" encoding= \"UTF-8\" ").toString());
2364+
"{version1.0= encoding= }",
2365+
Xml.parseAttributes(" version = 1.0\" encoding= \"UTF-8\" ").toString());
23642366
}
23652367

23662368
@SuppressWarnings("unchecked")

0 commit comments

Comments
 (0)