Skip to content

Commit

Permalink
build the correct error
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Feb 3, 2025
1 parent 90846ba commit 3925833
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/main/java/org/htmlunit/javascript/host/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -1535,9 +1535,12 @@ public static boolean matches(final Context context, final Scriptable scope,
return domNode != null && ((DomElement) domNode).matches(selectorString);
}
catch (final CSSException e) {
throw JavaScriptEngine.syntaxError(
"An invalid or illegal selector was specified (selector: '"
+ selectorString + "' error: " + e.getMessage() + ").");
throw JavaScriptEngine.asJavaScriptException(
(HtmlUnitScriptable) getTopLevelScope(thisObj),
new DOMException(
"An invalid or illegal selector was specified (selector: '"
+ selectorString + "' error: " + e.getMessage() + ").",
DOMException.SYNTAX_ERR));
}
}

Expand Down
43 changes: 42 additions & 1 deletion src/test/java/org/htmlunit/html/parser/MalformedHtmlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,20 @@ public void unknownTagInTbody() throws Exception {
+ "</tbody>"
+ "</table>"
+ "<script> function log(msg) { window.document.title += msg + '\\u00a7'; } "
+ "function logEx(e) { let toStr = null; "
+ "if (toStr === null && e instanceof EvalError) { toStr = ''; } "
+ "if (toStr === null && e instanceof RangeError) { toStr = ''; } "
+ "if (toStr === null && e instanceof ReferenceError) { toStr = ''; } "
+ "if (toStr === null && e instanceof SyntaxError) { toStr = ''; } "
+ "if (toStr === null && e instanceof TypeError) { toStr = ''; } "
+ "if (toStr === null && e instanceof URIError) { toStr = ''; } "
+ "if (toStr === null && e instanceof AggregateError) { toStr = '/AggregateError'; } "
+ "if (toStr === null && typeof InternalError == 'function' "
+ "&& e instanceof InternalError) { toStr = '/InternalError'; } "
+ "if (toStr === null) { let rx = /\\[object (.*)\\]/; "
+ "toStr = Object.prototype.toString.call(e); "
+ "let match = rx.exec(toStr); if (match != null) { toStr = '/' + match[1]; } } "
+ "log(e.name + toStr); } "
+ "log(document.getElementById('bdy').innerHTML); </script>")
public void formInTableData() throws Exception {
final String html = "<html>\n"
Expand Down Expand Up @@ -544,6 +558,20 @@ public void formInTableData() throws Exception {
+ "</tbody>"
+ "</table>"
+ "<script> function log(msg) { window.document.title += msg + '\\u00a7'; } "
+ "function logEx(e) { let toStr = null; "
+ "if (toStr === null && e instanceof EvalError) { toStr = ''; } "
+ "if (toStr === null && e instanceof RangeError) { toStr = ''; } "
+ "if (toStr === null && e instanceof ReferenceError) { toStr = ''; } "
+ "if (toStr === null && e instanceof SyntaxError) { toStr = ''; } "
+ "if (toStr === null && e instanceof TypeError) { toStr = ''; } "
+ "if (toStr === null && e instanceof URIError) { toStr = ''; } "
+ "if (toStr === null && e instanceof AggregateError) { toStr = '/AggregateError'; } "
+ "if (toStr === null && typeof InternalError == 'function' "
+ "&& e instanceof InternalError) { toStr = '/InternalError'; } "
+ "if (toStr === null) { let rx = /\\[object (.*)\\]/; "
+ "toStr = Object.prototype.toString.call(e); "
+ "let match = rx.exec(toStr); if (match != null) { toStr = '/' + match[1]; } } "
+ "log(e.name + toStr); } "
+ "log(document.getElementById('bdy').innerHTML); </script>")
public void formInTableRow() throws Exception {
final String html = "<html>\n"
Expand Down Expand Up @@ -591,8 +619,21 @@ public void formInTableRow() throws Exception {
+ "</tbody>"
+ "</table>"
+ "<script> function log(msg) { window.document.title += msg + '\\u00a7'; } "
+ "function logEx(e) { let toStr = null; "
+ "if (toStr === null && e instanceof EvalError) { toStr = ''; } "
+ "if (toStr === null && e instanceof RangeError) { toStr = ''; } "
+ "if (toStr === null && e instanceof ReferenceError) { toStr = ''; } "
+ "if (toStr === null && e instanceof SyntaxError) { toStr = ''; } "
+ "if (toStr === null && e instanceof TypeError) { toStr = ''; } "
+ "if (toStr === null && e instanceof URIError) { toStr = ''; } "
+ "if (toStr === null && e instanceof AggregateError) { toStr = '/AggregateError'; } "
+ "if (toStr === null && typeof InternalError == 'function' "
+ "&& e instanceof InternalError) { toStr = '/InternalError'; } "
+ "if (toStr === null) { let rx = /\\[object (.*)\\]/; "
+ "toStr = Object.prototype.toString.call(e); "
+ "let match = rx.exec(toStr); if (match != null) { toStr = '/' + match[1]; } } "
+ "log(e.name + toStr); } "
+ "log(document.getElementById('bdy').innerHTML); </script>")

public void formInTable() throws Exception {
final String html = "<html>\n"
+ "<body id='bdy'>\n"
Expand Down

0 comments on commit 3925833

Please sign in to comment.