bito-code-review[bot] commented on code in PR #42489:
URL: https://github.com/apache/superset/pull/42489#discussion_r4078815914
##########
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:
<div>
<div id="suggestion">
<div id="issue"><b>Broken HTML detection regex</b></div>
<div id="fix">
Both regexes are over-escaped, so the new logic never fires.
`/^<([a-z][a-z0-9]*)\\b/i` matches a literal backslash, not a word boundary, so
`leadingTag` is always `null` and `checkForHtml` returns `false` for every
non-doctype HTML page (e.g. `<html><body>502 Bad Gateway</body></html>`). The
`\\s*` in the template literal likewise yields a literal-backslash regex.
Result: HTML error pages are no longer collapsed to a status message
(regression vs the old `!isJsonString && isProbablyHTML`). Use `\b` and `\s*`.
</div>
</div>
<small><i>Code Review Run #6783c4</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]