bito-code-review[bot] commented on code in PR #42489:
URL: https://github.com/apache/superset/pull/42489#discussion_r4140415030


##########
superset-frontend/packages/superset-ui-core/src/query/getClientErrorObject.ts:
##########
@@ -89,7 +89,34 @@ const ERROR_CODE_LOOKUP = {
 };
 
 export function checkForHtml(str: string): boolean {
-  return !isJsonString(str) && isProbablyHTML(str);
+  // An HTML error page served by a proxy or gateway begins with markup, and
+  // has no message worth showing. A server-authored error that merely quotes
+  // a tag — a database syntax error echoing back the offending `<a>`, say —
+  // begins with prose, and is the whole point of the response. Only the
+  // former may be collapsed into a generic status message.
+  //
+  // A leading `<` alone isn't enough: a message that opens with a quoted,
+  // unclosed tag (`<a> is not valid syntax`) also starts with `<`, and
+  // isProbablyHTML()'s DOMParser auto-closes stray tags on parse, so it
+  // can't tell that case apart either. Requiring the leading tag to actually
+  // close somewhere in the string does: a real fragment like
+  // `<div>500: Internal Server Error</div>` closes what it opens, a quoted
+  // tag doesn't. A `<!doctype html>` preamble is exempt from this check
+  // since isProbablyHTML() already gates that case on its own.
+  if (isJsonString(str)) {
+    return false;
+  }
+  const trimmed = str.trimStart();
+  if (!trimmed.startsWith('<')) {
+    return false;
+  }
+  if (!/^<!doctype html>/i.test(trimmed)) {
+    const leadingTag = trimmed.match(/^<([a-z][a-z0-9]*)\b/i)?.[1];
+    if (!leadingTag || !new RegExp(`</${leadingTag}\\s*>`, 'i').test(str)) {

Review Comment:
   <!-- Bito Reply -->
   The reviewer's suggestion to use `\b` and `\s*` is correct. In JavaScript 
regex literals, `\b` and `\s` are interpreted as the word boundary and 
whitespace character classes, respectively. The reviewer's concern about 
over-escaping is valid; using double backslashes `\\b` and `\\s` inside a regex 
literal would indeed match literal backslashes, which would break the intended 
logic.
   
   
**superset-frontend/packages/superset-ui-core/src/query/getClientErrorObject.ts**
   ```
   const leadingTag = trimmed.match(/^<([a-z][a-z0-9]*)\b/i)?.[1];
       if (!leadingTag || !new RegExp(`</${leadingTag}\s*>`, 'i').test(str)) {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to