diff options
Diffstat (limited to 'gnu/javax/swing/text/html/parser')
4 files changed, 42 insertions, 29 deletions
diff --git a/gnu/javax/swing/text/html/parser/htmlValidator.java b/gnu/javax/swing/text/html/parser/htmlValidator.java index 4d287a677..7507850e8 100644 --- a/gnu/javax/swing/text/html/parser/htmlValidator.java +++ b/gnu/javax/swing/text/html/parser/htmlValidator.java @@ -153,7 +153,7 @@ public abstract class htmlValidator * Remove the given tag from the stack or (if found) from the list * of the forcibly closed tags. */ - public void closeTag(TagElement tElement) + public boolean closeTag(TagElement tElement) { HTML.Tag tag = tElement.getHTMLTag(); hTag x; @@ -191,11 +191,12 @@ public abstract class htmlValidator } stack.remove(x); - return; + return true; } } } s_error("Closing unopened <" + tag + ">"); + return false; } /** diff --git a/gnu/javax/swing/text/html/parser/support/Parser.java b/gnu/javax/swing/text/html/parser/support/Parser.java index f1f25fad0..98058e503 100644 --- a/gnu/javax/swing/text/html/parser/support/Parser.java +++ b/gnu/javax/swing/text/html/parser/support/Parser.java @@ -659,19 +659,18 @@ 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] != ' ') - || validator.tagIsValidForContext(pcdata) == Boolean.TRUE) - { - attributes = htmlAttributeSet.EMPTY_HTML_ATTRIBUTE_SET; - _handleEmptyTag(pcdata); + attributes = htmlAttributeSet.EMPTY_HTML_ATTRIBUTE_SET; + _handleEmptyTag(pcdata); - handleText(text); - if (titleOpen) - title.append(text); - } + handleText(text); + if (titleOpen) + title.append(text); } } @@ -1197,8 +1196,8 @@ public class Parser */ private void _handleEndTag(TagElement tag) { - validator.closeTag(tag); - _handleEndTag_remaining(tag); + if (validator.closeTag(tag)) + _handleEndTag_remaining(tag); } /** @@ -1218,6 +1217,11 @@ public class Parser if (preformatted < 0) preformatted = 0; + // When a block tag is closed, consume whitespace that follows after + // it. + if (h.isBlock()) + optional(WS); + if (h == HTML.Tag.TITLE) { titleOpen = false; @@ -1460,7 +1464,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); |