diff options
author | Roman Kennke <roman@kennke.org> | 2006-11-15 10:52:15 +0000 |
---|---|---|
committer | Roman Kennke <roman@kennke.org> | 2006-11-15 10:52:15 +0000 |
commit | e54f60215b005f0a1957afe55e0dc8bc5c3518e6 (patch) | |
tree | 06892376f04a6d4212f6a8f6ed48de583adfe80b /gnu | |
parent | 0037c3e3a698f89c8b89ff01ab07837d4624a322 (diff) | |
download | classpath-e54f60215b005f0a1957afe55e0dc8bc5c3518e6.tar.gz |
2006-11-15 Roman Kennke <kennke@aicas.com>
* gnu/javax/swing/text/html/parser/support/Parser.java
(_handleText): Consume whitespace directly before a closing tag.
(restOfTag): Consume whitespace directly after opening.
* gnu/javax/swing/text/html/parser/support/textPreProcessor.java
(preprocess): Don't perform array boundary checking by
catch AIOOBE, instead check the boundary in loop condition.
* gnu/javax/swing/text/html/parser/support/low/Constants.java
(TAG_CLOSE): New constants. Describes the token pattern for
a closing tag.
Diffstat (limited to 'gnu')
3 files changed, 27 insertions, 16 deletions
diff --git a/gnu/javax/swing/text/html/parser/support/Parser.java b/gnu/javax/swing/text/html/parser/support/Parser.java index f1f25fad0..9c10f68fc 100644 --- a/gnu/javax/swing/text/html/parser/support/Parser.java +++ b/gnu/javax/swing/text/html/parser/support/Parser.java @@ -659,7 +659,10 @@ public class Parser else text = textProcessor.preprocess(buffer); - if (text != null && text.length > 0) + if (text != null && text.length > 0 + // According to the specs we need to discard whitespace immediately + // before a closing tag. + && (text.length > 1 || (text[0] == ' ' && ! TAG_CLOSE.matches(this)))) { TagElement pcdata = new TagElement(dtd.getElement("#pcdata")); if ((text.length > 1 && text[0] != ' ') @@ -1460,7 +1463,12 @@ public class Parser if (te.getElement().type == DTDConstants.EMPTY) _handleEmptyTag(te); else - _handleStartTag(te); + { + // According to the specs we need to consume whitespace following + // immediately after a opening tag. + optional(WS); + _handleStartTag(te); + } } } diff --git a/gnu/javax/swing/text/html/parser/support/low/Constants.java b/gnu/javax/swing/text/html/parser/support/low/Constants.java index 283d32385..5416582ad 100644 --- a/gnu/javax/swing/text/html/parser/support/low/Constants.java +++ b/gnu/javax/swing/text/html/parser/support/low/Constants.java @@ -209,6 +209,17 @@ public class Constants } ); + /** + * Ordinary HTML tag closing pattern. + */ + public static final pattern TAG_CLOSE = + new pattern(new node[] + { + new node(BEGIN), new node(WS, true), new node(SLASH), + new node(WS, true), new node(NUMTOKEN) + } + ); + /* Special tokens */ /** diff --git a/gnu/javax/swing/text/html/parser/support/textPreProcessor.java b/gnu/javax/swing/text/html/parser/support/textPreProcessor.java index b81275b1f..6fd79e258 100644 --- a/gnu/javax/swing/text/html/parser/support/textPreProcessor.java +++ b/gnu/javax/swing/text/html/parser/support/textPreProcessor.java @@ -65,22 +65,14 @@ public class textPreProcessor int b = text.length - 1; // Remove leading/trailing whitespace, leaving at most one character - try - { - while (Constants.bWHITESPACE.get(text[a]) - && Constants.bWHITESPACE.get(text[a + 1])) - a++; + int len = text.length; + while (a + 1 < len && Constants.bWHITESPACE.get(text[a]) + && Constants.bWHITESPACE.get(text[a + 1])) + a++; - while (b > a && Constants.bWHITESPACE.get(text[b]) + while (b > a && Constants.bWHITESPACE.get(text[b]) && Constants.bWHITESPACE.get(text[b - 1])) - b--; - } - catch (ArrayIndexOutOfBoundsException sx) - { - // A text fragment, consisting from spaces and line breaks only, - // mutates into single space. - return new char[] { ' ' }; - } + b--; a_text.setLength(0); |