Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/java/org/htmlunit/cyberneko/HTMLScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,16 @@ protected int scanEntityRef(final XMLString str, final XMLString plainValue, fin
}
return returnEntityRefString(str, content);
}

if ('&' == nextChar) {
fCurrentEntity.rewind(1);
if (plainValue != null) {
plainValue.append('&');
}
str.clearAndAppend('&');
return returnEntityRefString(str, content);
}

str.append((char) nextChar);

if ('#' == nextChar) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public void setMatchFromCode() {
// a surrogate-character-reference parse error. Set the character reference code to 0xFFFD
if (Character.isSurrogate((char) code_)) {
match_ = "\uFFFD";
matchLength_ = consumedCount_;
return;
}

Expand Down Expand Up @@ -196,7 +197,7 @@ public void setMatchFromCode() {
return;

case 0x98:
match_ = "\u20DC";
match_ = "\u02DC";
matchLength_ = consumedCount_;
return;

Expand Down
36 changes: 36 additions & 0 deletions src/test/java/org/htmlunit/cyberneko/GeneralTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
private static final String[] FEATURES = {"http://cyberneko.org/html/features/augmentations"};

@Test
public void newlineInAttributeCrLf() throws Exception {

Check warning on line 47 in src/test/java/org/htmlunit/cyberneko/GeneralTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit-neko&issues=AZ4DX779mI3dEVJdoggL&open=AZ4DX779mI3dEVJdoggL&pullRequest=172
String expected =
"[synth](html" + NL
+ "[synth](head" + NL
Expand Down Expand Up @@ -87,7 +87,7 @@
}

@Test
public void newlineInAttributeLf() throws Exception {

Check warning on line 90 in src/test/java/org/htmlunit/cyberneko/GeneralTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit-neko&issues=AZ4DX779mI3dEVJdoggM&open=AZ4DX779mI3dEVJdoggM&pullRequest=172
String expected =
"[synth](html" + NL
+ "[synth](head" + NL
Expand Down Expand Up @@ -133,7 +133,7 @@
}

@Test
public void newlineInPiCrLf() throws Exception {

Check warning on line 136 in src/test/java/org/htmlunit/cyberneko/GeneralTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit-neko&issues=AZ4DX779mI3dEVJdoggN&open=AZ4DX779mI3dEVJdoggN&pullRequest=172
String expected =
"[synth](html" + NL
+ "[synth](head" + NL
Expand Down Expand Up @@ -170,7 +170,7 @@
}

@Test
public void newlineInPiLf() throws Exception {

Check warning on line 173 in src/test/java/org/htmlunit/cyberneko/GeneralTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit-neko&issues=AZ4DX779mI3dEVJdoggO&open=AZ4DX779mI3dEVJdoggO&pullRequest=172
String expected =
"[synth](html" + NL
+ "[synth](head" + NL
Expand Down Expand Up @@ -239,7 +239,7 @@
}

@Test
public void parseInputSourceReplacement() throws Exception {

Check warning on line 242 in src/test/java/org/htmlunit/cyberneko/GeneralTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit-neko&issues=AZ4DX779mI3dEVJdoggP&open=AZ4DX779mI3dEVJdoggP&pullRequest=172
final DOMParser parser = new DOMParser(HTMLDocumentImpl.class);

final StringWriter out = new StringWriter();
Expand All @@ -262,7 +262,7 @@
}

@Test
public void parseInputSourceResolvesToReplacement() throws Exception {

Check warning on line 265 in src/test/java/org/htmlunit/cyberneko/GeneralTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit-neko&issues=AZ4DX779mI3dEVJdoggQ&open=AZ4DX779mI3dEVJdoggQ&pullRequest=172
final DOMParser parser = new DOMParser(HTMLDocumentImpl.class);

final StringWriter out = new StringWriter();
Expand All @@ -285,7 +285,7 @@
}

@Test
public void parseInputSourceIANAEncoding() throws Exception {

Check warning on line 288 in src/test/java/org/htmlunit/cyberneko/GeneralTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit-neko&issues=AZ4DX779mI3dEVJdoggR&open=AZ4DX779mI3dEVJdoggR&pullRequest=172
final DOMParser parser = new DOMParser(HTMLDocumentImpl.class);

final StringWriter out = new StringWriter();
Expand Down Expand Up @@ -315,4 +315,40 @@
+ ")html";
assertEquals(expected.trim(), out.toString().trim());
}

@Test
public void textContentConsecutiveAmpersandsBeforeNamedEntity() throws Exception {

Check warning on line 320 in src/test/java/org/htmlunit/cyberneko/GeneralTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit-neko&issues=AZ4DX779mI3dEVJdoggS&open=AZ4DX779mI3dEVJdoggS&pullRequest=172
final String expected = "(html" + NL
+ "(head" + NL
+ ")head" + NL
+ "(body" + NL
+ "\"FOO&&&>BAR" + NL
+ ")body" + NL
+ ")html";
doTest("FOO&&&>BAR", null, expected);
}

@Test
public void textContentSurrogateNumericReference() throws Exception {

Check warning on line 332 in src/test/java/org/htmlunit/cyberneko/GeneralTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit-neko&issues=AZ4DX779mI3dEVJdoggT&open=AZ4DX779mI3dEVJdoggT&pullRequest=172
final String expected = "(html" + NL
+ "(head" + NL
+ ")head" + NL
+ "(body" + NL
+ "\"FOO\uFFFDZOO" + NL
+ ")body" + NL
+ ")html";
doTest("FOO�ZOO", null, expected);
}

@Test
public void textContentWindows1252ControlMapping() throws Exception {

Check warning on line 344 in src/test/java/org/htmlunit/cyberneko/GeneralTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit-neko&issues=AZ4DX779mI3dEVJdoggU&open=AZ4DX779mI3dEVJdoggU&pullRequest=172
final String expected = "(html" + NL
+ "(head" + NL
+ ")head" + NL
+ "(body" + NL
+ "\"FOO\u02DCZOO" + NL
+ ")body" + NL
+ ")html";
doTest("FOO˜ZOO", null, expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
* @author René Schwietzke
* @author Ronald Brill
*/
public class HTMLUnicodeEntitiesParserTest {

Check warning on line 29 in src/test/java/org/htmlunit/cyberneko/HTMLUnicodeEntitiesParserTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit-neko&issues=AZ4DX73mmI3dEVJdoggJ&open=AZ4DX73mmI3dEVJdoggJ&pullRequest=172
@Test
public void parseEuro() {

Check warning on line 31 in src/test/java/org/htmlunit/cyberneko/HTMLUnicodeEntitiesParserTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit-neko&issues=AZ4DX73mmI3dEVJdogf8&open=AZ4DX73mmI3dEVJdogf8&pullRequest=172

Check warning on line 31 in src/test/java/org/htmlunit/cyberneko/HTMLUnicodeEntitiesParserTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace these 12 tests with a single Parameterized one.

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit-neko&issues=AZ4DX73mmI3dEVJdoggK&open=AZ4DX73mmI3dEVJdoggK&pullRequest=172
final HTMLUnicodeEntitiesParser parser = new HTMLUnicodeEntitiesParser();

final String input = "x80;";
Expand All @@ -42,7 +42,7 @@
}

@Test
public void parseEuroUppercase() {

Check warning on line 45 in src/test/java/org/htmlunit/cyberneko/HTMLUnicodeEntitiesParserTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit-neko&issues=AZ4DX73mmI3dEVJdogf9&open=AZ4DX73mmI3dEVJdogf9&pullRequest=172
final HTMLUnicodeEntitiesParser parser = new HTMLUnicodeEntitiesParser();

final String input = "X80;";
Expand All @@ -56,7 +56,7 @@
}

@Test
public void parseBroken() {

Check warning on line 59 in src/test/java/org/htmlunit/cyberneko/HTMLUnicodeEntitiesParserTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit-neko&issues=AZ4DX73mmI3dEVJdogf-&open=AZ4DX73mmI3dEVJdogf-&pullRequest=172
final HTMLUnicodeEntitiesParser parser = new HTMLUnicodeEntitiesParser();

final String input = "A80;";
Expand All @@ -70,7 +70,7 @@
}

@Test
public void parseLTAsDecimal() {

Check warning on line 73 in src/test/java/org/htmlunit/cyberneko/HTMLUnicodeEntitiesParserTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit-neko&issues=AZ4DX73mmI3dEVJdogf_&open=AZ4DX73mmI3dEVJdogf_&pullRequest=172
final HTMLUnicodeEntitiesParser parser = new HTMLUnicodeEntitiesParser();

final String input = "60;";
Expand All @@ -84,7 +84,7 @@
}

@Test
public void parseLTAsDecimalBroken() {

Check warning on line 87 in src/test/java/org/htmlunit/cyberneko/HTMLUnicodeEntitiesParserTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit-neko&issues=AZ4DX73mmI3dEVJdoggA&open=AZ4DX73mmI3dEVJdoggA&pullRequest=172
final HTMLUnicodeEntitiesParser parser = new HTMLUnicodeEntitiesParser();

final String input = "60 ";
Expand All @@ -98,7 +98,7 @@
}

@Test
public void parseEuroMissingSemicolon() {

Check warning on line 101 in src/test/java/org/htmlunit/cyberneko/HTMLUnicodeEntitiesParserTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit-neko&issues=AZ4DX73mmI3dEVJdoggB&open=AZ4DX73mmI3dEVJdoggB&pullRequest=172
final HTMLUnicodeEntitiesParser parser = new HTMLUnicodeEntitiesParser();

final String input = "x80<";
Expand All @@ -112,7 +112,7 @@
}

@Test
public void parseNullChar() {

Check warning on line 115 in src/test/java/org/htmlunit/cyberneko/HTMLUnicodeEntitiesParserTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit-neko&issues=AZ4DX73mmI3dEVJdoggC&open=AZ4DX73mmI3dEVJdoggC&pullRequest=172
final HTMLUnicodeEntitiesParser parser = new HTMLUnicodeEntitiesParser();

final String input = "x00;";
Expand All @@ -126,7 +126,7 @@
}

@Test
public void parseOverflowRange() {

Check warning on line 129 in src/test/java/org/htmlunit/cyberneko/HTMLUnicodeEntitiesParserTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit-neko&issues=AZ4DX73mmI3dEVJdoggD&open=AZ4DX73mmI3dEVJdoggD&pullRequest=172
final HTMLUnicodeEntitiesParser parser = new HTMLUnicodeEntitiesParser();

final String input = "x11FFFF;";
Expand All @@ -140,7 +140,7 @@
}

@Test
public void parseSurrogate() {

Check warning on line 143 in src/test/java/org/htmlunit/cyberneko/HTMLUnicodeEntitiesParserTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit-neko&issues=AZ4DX73mmI3dEVJdoggE&open=AZ4DX73mmI3dEVJdoggE&pullRequest=172
final HTMLUnicodeEntitiesParser parser = new HTMLUnicodeEntitiesParser();

final String input = "xD800;";
Expand All @@ -150,11 +150,25 @@
}

assertEquals("\uFFFD", parser.getMatch());
assertEquals(6, parser.getRewindCount());
assertEquals(0, parser.getRewindCount());
}

@Test
public void parseWindows1252SmallTilde() {

Check warning on line 157 in src/test/java/org/htmlunit/cyberneko/HTMLUnicodeEntitiesParserTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit-neko&issues=AZ4DX73mmI3dEVJdoggF&open=AZ4DX73mmI3dEVJdoggF&pullRequest=172
final HTMLUnicodeEntitiesParser parser = new HTMLUnicodeEntitiesParser();

final String input = "x98;";
int i = 0;
while (parser.parseNumeric(input.charAt(i))) {
i++;
}

assertEquals("\u02DC", parser.getMatch());
assertEquals(0, parser.getRewindCount());
}

@Test
public void parseNonCharacterLow() {

Check warning on line 171 in src/test/java/org/htmlunit/cyberneko/HTMLUnicodeEntitiesParserTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit-neko&issues=AZ4DX73mmI3dEVJdoggG&open=AZ4DX73mmI3dEVJdoggG&pullRequest=172
final HTMLUnicodeEntitiesParser parser = new HTMLUnicodeEntitiesParser();

final String input = "x80;";
Expand All @@ -168,7 +182,7 @@
}

@Test
public void parseNonCharacterHighLowercase() {

Check warning on line 185 in src/test/java/org/htmlunit/cyberneko/HTMLUnicodeEntitiesParserTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit-neko&issues=AZ4DX73mmI3dEVJdoggH&open=AZ4DX73mmI3dEVJdoggH&pullRequest=172
final HTMLUnicodeEntitiesParser parser = new HTMLUnicodeEntitiesParser();

final String input = "x9f;";
Expand All @@ -182,7 +196,7 @@
}

@Test
public void parseNonCharacterHighUppercase() {

Check warning on line 199 in src/test/java/org/htmlunit/cyberneko/HTMLUnicodeEntitiesParserTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=HtmlUnit_htmlunit-neko&issues=AZ4DX73mmI3dEVJdoggI&open=AZ4DX73mmI3dEVJdoggI&pullRequest=172
final HTMLUnicodeEntitiesParser parser = new HTMLUnicodeEntitiesParser();

final String input = "x9F;";
Expand Down