Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[html] validation error on JavaScript block comment with arrow in HTML script #171153

Open
mpf82 opened this issue Jan 12, 2023 · 5 comments · May be fixed by #240932
Open

[html] validation error on JavaScript block comment with arrow in HTML script #171153

mpf82 opened this issue Jan 12, 2023 · 5 comments · May be fixed by #240932
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug html HTML support issues
Milestone

Comments

@mpf82
Copy link

mpf82 commented Jan 12, 2023

Does this issue occur when all extensions are disabled?

Yes, all extensions have been disabled for the workspace

VS Code / OS

  • VS Code Version: 1.74.3
  • OS Version: Windows 10 Pro, 64-Bit

Steps to Reproduce

Create a HTML file with the following content:

<script>
/* --> */
</script>

🙁 Actual behavior

Console shows 2 problems:

  • Expression expected.
  • Unterminated regular expression literal.

Full errors:

[{
"resource": "test.html",
"owner": "generated_diagnostic_collection_name#1",
"severity": 8,
"message": "Expression expected.",
"source": "javascript",
"startLineNumber": 2,
"startColumn": 8,
"endLineNumber": 2,
"endColumn": 9
}]

[{
"resource": "test.html",
"owner": "generated_diagnostic_collection_name#1",
"severity": 8,
"message": "Unterminated regular expression literal.",
"source": "javascript",
"startLineNumber": 2,
"startColumn": 10,
"endLineNumber": 2,
"endColumn": 10
}]


It even shows more errors for every pair of -- within the comment block.

e.g.

<script>
/* --> ----------------------------- */
</script>

Results in a total of 16 errors logged (15 x expression expected, 1 x Unterminated regular expression literal.)

🙂 Expected behavior

Ignore whatever is in comments.

@aeschli aeschli added html HTML support issues bug Issue identified by VS Code Team member as probable bug labels Jan 12, 2023
@aeschli aeschli added this to the On Deck milestone Jan 12, 2023
@Mayuresh0072
Copy link

@aeschli Is the issue still open, if its not solved please assign me this issue. Thanks.

@aeschli
Copy link
Contributor

aeschli commented Mar 1, 2023

@Mayuresh0072 If you want to try to fix this, you are very welcome! Just start a PR and link to this issue. I think the problem is here: https://github.com/microsoft/vscode/blob/main/extensions/html-language-features/server/src/modes/embeddedSupport.ts#L199

@mpf82
Copy link
Author

mpf82 commented Mar 1, 2023

@aeschli You're probably right.

I've been fiddling with the dist (htmlServerMain.js), changing

function s(e,t){return e.attributeValue||"javascript"!==e.languageId?t:t.replace("\x3c!--","/* ").replace("--\x3e"," */")}

to

function s(e,t){return e.attributeValue||"javascript"!==e.languageId?t:t}

and the messages in the console are gone.

@aeschli
Copy link
Contributor

aeschli commented Mar 2, 2023

That's too simple. We still need to remove the HTML comments from the script. But the fix could be to clear them out instead replacing with /* and */

@aeschli aeschli changed the title JavaScript block comment with arrow in HTML script - Expression expected / Unterminated regular expression literal. [html] validation error on JavaScript block comment with arrow in HTML script Dec 12, 2024
@Vector341
Copy link

return content.replace(`<!--`, `/* `).replace(`-->`, ` */`);

It's interesting that replace(pattern: string, replacement: string) is used, which means only the FIRST occurrence of <!-- and --> will be replaced.
Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug html HTML support issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants