@Test public void replaceHtmlEntities() { PotentialBracketEndDelimiter delimiter = new PotentialBracketEndDelimiter(line, 0); Escaper escaper = UrlEscapers.urlFormParameterEscaper(); assertEquals("asf", delimiter.replaceHtmlEntities("asf", escaper)); assertEquals("&amp", delimiter.replaceHtmlEntities("&amp", escaper)); assertEquals("&amp ;", delimiter.replaceHtmlEntities("&amp ;", escaper)); assertEquals("%26", delimiter.replaceHtmlEntities("&amp;", escaper)); assertEquals("a%26", delimiter.replaceHtmlEntities("a&amp;", escaper)); assertEquals("a%26b", delimiter.replaceHtmlEntities("a&amp;b", escaper)); assertEquals("%C3%A4", delimiter.replaceHtmlEntities("&auml;", escaper)); assertEquals("&", delimiter.replaceHtmlEntities("&amp;", null)); assertEquals("\"", delimiter.replaceHtmlEntities("&quot;", null)); assertEquals("\u00e4", delimiter.replaceHtmlEntities("&auml;", null)); assertEquals("&xdfsldk;", delimiter.replaceHtmlEntities("&xdfsldk;", null)); assertEquals("&0;", delimiter.replaceHtmlEntities("&0;", null)); }
String replaceHtmlEntities(String text, Escaper escaper) { String replaced = ""; int lastEnd = 0; Matcher matcher = HTML_ENTITY_PATTERN.matcher(text); while (matcher.find()) { if (lastEnd < matcher.start(1)) { replaced += text.substring(lastEnd, matcher.start(1)); } String entity = matcher.group(2); String entityTextEquivalent = EntityReferences.instance().equivalentString(entity); replaced += entityTextEquivalent == null ? matcher.group(1) : escaper == null ? entityTextEquivalent : escaper.escape(entityTextEquivalent); lastEnd = matcher.end(1); } if (lastEnd < text.length()) { replaced += text.substring(lastEnd, text.length()); } return replaced; }
PotentialBracketEndDelimiter extends InlineWithText { String replaceHtmlEntities(String text, Escaper escaper) { String replaced = ""; int lastEnd = 0; Matcher matcher = HTML_ENTITY_PATTERN.matcher(text); while (matcher.find()) { if (lastEnd < matcher.start(1)) { replaced += text.substring(lastEnd, matcher.start(1)); } String entity = matcher.group(2); String entityTextEquivalent = EntityReferences.instance().equivalentString(entity); replaced += entityTextEquivalent == null ? matcher.group(1) : escaper == null ? entityTextEquivalent : escaper.escape(entityTextEquivalent); lastEnd = matcher.end(1); } if (lastEnd < text.length()) { replaced += text.substring(lastEnd, text.length()); } return replaced; } }
PotentialBracketEndDelimiter extends InlineWithText { String replaceHtmlEntities(String text, Escaper escaper) { String replaced = ""; int lastEnd = 0; Matcher matcher = HTML_ENTITY_PATTERN.matcher(text); while (matcher.find()) { if (lastEnd < matcher.start(1)) { replaced += text.substring(lastEnd, matcher.start(1)); } String entity = matcher.group(2); String entityTextEquivalent = EntityReferences.instance().equivalentString(entity); replaced += entityTextEquivalent == null ? matcher.group(1) : escaper == null ? entityTextEquivalent : escaper.escape(entityTextEquivalent); lastEnd = matcher.end(1); } if (lastEnd < text.length()) { replaced += text.substring(lastEnd, text.length()); } return replaced; } PotentialBracketEndDelimiter(Line line, int offset); }
PotentialBracketEndDelimiter extends InlineWithText { String replaceHtmlEntities(String text, Escaper escaper) { String replaced = ""; int lastEnd = 0; Matcher matcher = HTML_ENTITY_PATTERN.matcher(text); while (matcher.find()) { if (lastEnd < matcher.start(1)) { replaced += text.substring(lastEnd, matcher.start(1)); } String entity = matcher.group(2); String entityTextEquivalent = EntityReferences.instance().equivalentString(entity); replaced += entityTextEquivalent == null ? matcher.group(1) : escaper == null ? entityTextEquivalent : escaper.escape(entityTextEquivalent); lastEnd = matcher.end(1); } if (lastEnd < text.length()) { replaced += text.substring(lastEnd, text.length()); } return replaced; } PotentialBracketEndDelimiter(Line line, int offset); @Override void emit(DocumentBuilder builder); @Override void apply(ProcessingContext context, List<Inline> inlines, Cursor cursor); void truncate(List<Inline> inlines, int indexOfOpeningDelimiter); }
PotentialBracketEndDelimiter extends InlineWithText { String replaceHtmlEntities(String text, Escaper escaper) { String replaced = ""; int lastEnd = 0; Matcher matcher = HTML_ENTITY_PATTERN.matcher(text); while (matcher.find()) { if (lastEnd < matcher.start(1)) { replaced += text.substring(lastEnd, matcher.start(1)); } String entity = matcher.group(2); String entityTextEquivalent = EntityReferences.instance().equivalentString(entity); replaced += entityTextEquivalent == null ? matcher.group(1) : escaper == null ? entityTextEquivalent : escaper.escape(entityTextEquivalent); lastEnd = matcher.end(1); } if (lastEnd < text.length()) { replaced += text.substring(lastEnd, text.length()); } return replaced; } PotentialBracketEndDelimiter(Line line, int offset); @Override void emit(DocumentBuilder builder); @Override void apply(ProcessingContext context, List<Inline> inlines, Cursor cursor); void truncate(List<Inline> inlines, int indexOfOpeningDelimiter);  }