diff options
author | Elliott Hughes <enh@google.com> | 2009-11-16 21:23:11 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2009-11-17 11:43:41 -0800 |
commit | 6bcf32ab404c39b85d25430f6df16503ef3526cf (patch) | |
tree | 473ec3f8d56e671087b982736e7d017dfa804554 /xml/src/main/java/org/kxml2 | |
parent | d2bed869f45bd0f286f5916e58cdacde8bd66397 (diff) | |
download | libcore-6bcf32ab404c39b85d25430f6df16503ef3526cf.zip libcore-6bcf32ab404c39b85d25430f6df16503ef3526cf.tar.gz libcore-6bcf32ab404c39b85d25430f6df16503ef3526cf.tar.bz2 |
Various XML fixes.
Add tests for bug 2487, exploring the situations where "]]>" is and isn't
allowed. Fix the bug by changing KXmlParser so it pays attention to
whether it's dealing with normal text or text in an attribute value and
reports errors appropriately.
In order to pass the new tests, we also need to fix DocumentBuilder to
pay attention to its DocumentBuilderFactory's "coalescing" setting: whether
or not adjacent text/CDATA nodes should be coalesced.
This in turn fixes a @KnownFailure in DocumentBuilderFactoryTest: previously
we didn't allow the caller to turn "coalescing" off (though until my
previous patch, we didn't actually coalesce anyway). Now we support both,
and I've made coalescing the default, because bug reports tell us that's
what users want. It's how the RI behaves, too.
Bug: 2487
Diffstat (limited to 'xml/src/main/java/org/kxml2')
-rw-r--r-- | xml/src/main/java/org/kxml2/io/KXmlParser.java | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/xml/src/main/java/org/kxml2/io/KXmlParser.java b/xml/src/main/java/org/kxml2/io/KXmlParser.java index 98aae04..c4d8f3d 100644 --- a/xml/src/main/java/org/kxml2/io/KXmlParser.java +++ b/xml/src/main/java/org/kxml2/io/KXmlParser.java @@ -319,7 +319,9 @@ public class KXmlParser implements XmlPullParser { return; case TEXT : - pushText('<', !token); + // BEGIN android-changed: distinguish attribute values from normal text. + pushText('<', !token, false); + // END android-changed if (depth == 0) { if (isWhitespace) type = IGNORABLE_WHITESPACE; @@ -680,7 +682,9 @@ public class KXmlParser implements XmlPullParser { read(); int p = txtPos; - pushText(delimiter, true); + // BEGIN android-changed: distinguish attribute values from normal text. + pushText(delimiter, true, true); + // END android-changed attributes[i] = get(p); txtPos = p; @@ -800,7 +804,7 @@ public class KXmlParser implements XmlPullParser { ' ': parse to whitespace or '>' */ - private final void pushText(int delimiter, boolean resolveEntities) + private final void pushText(int delimiter, boolean resolveEntities, boolean inAttributeValue) throws IOException, XmlPullParserException { int next = peek(0); @@ -812,21 +816,31 @@ public class KXmlParser implements XmlPullParser { if (next <= ' ' || next == '>') break; + // BEGIN android-changed: "<" is not allowed in attribute values. if (next == '&') { if (!resolveEntities) break; pushEntity(); } + else if (next == '<' && inAttributeValue) { + error("Illegal: \"<\" inside attribute value"); + } else if (next == '\n' && type == START_TAG) { read(); push(' '); } else push(read()); + // END android-changed - if (next == '>' && cbrCount >= 2 && delimiter != ']') - error("Illegal: ]]>"); + // BEGIN android-changed: "]]>" *is* allowed in attribute values, but + // is not allowed in regular text between markup. + final boolean allowCloseCdata = inAttributeValue; + if (!allowCloseCdata && (next == '>' && cbrCount >= 2 && delimiter != ']')) { + error("Illegal: \"]]>\" outside CDATA section"); + } + // END android-changed if (next == ']') cbrCount++; |