microsoft / microsoft/monaco-editor
[Bug] Java syntax highlighting does not handle unicode escape sequences
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 46.8k
- Forks
- 4.1k
- Avg merge
- 17h 58m
- Merged PRs (30d)
- 1
Description
Reproducible in vscode.dev or in VS Code Desktop?
- Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
- Not reproducible in the monaco editor playground
Monaco Editor Playground Code
monaco.editor.create(document.getElementById('container'), {
value: '// \\u000a is a line break in Java unicode escapes\n// This comment \\u000a int[] x = {0}; // is actually code\nclass Test {\n // \\u0048\\u0065\\u006C\\u006C\\u006F\n public static void main(String[] args) {}\n}',
language: 'java'
});
Description
Java processes unicode escape sequences (\uXXXX) at a very early stage — before tokenisation. This means \u000a inside a comment is actually a line break, and code after it is executable. The syntax highlighter doesn't account for this, so what appears to be a comment can hide real code.
This is a known Java "feature" that can be used to hide malicious code: https://wh0.github.io/2019/11/16/easter-egg-inspection.html
Ideally the Java tokeniser would process \uXXXX sequences the same way javac does, or at minimum flag them visually.
Cross-reference: https://github.com/compiler-explorer/compiler-explorer/issues/4223
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Monaco editor playground reproduction and inspect the Java tokenizer's handling of unicode escapes, using the linked compiler-explorer issue for comparison. Done means comments containing Java escapes such as \u000a are tokenized according to Java's preprocessing behavior, or the sequences are visibly flagged as requested.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100