Comments (6)
Hi Clement!
This is probably harder to fix in js-mode
, which relies on what font-lock
considers a newline.
Here's a quick patch you can try, though there are probably more places that will need updating:
diff --git a/js2-mode.el b/js2-mode.el
index 11ebb37..d53c399 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -5585,16 +5585,17 @@ Increments `js2-ts-lineno' if the return value is a newline char.
Updates `js2-ts-cursor' to the point after the returned char.
Returns `js2-EOF_CHAR' if we hit the end of the buffer.
Also updates `js2-ts-hit-eof' and `js2-ts-line-start' as needed."
+ (defvar js2-eol-chars)
(let (c)
;; check for end of buffer
(if (>= js2-ts-cursor (point-max))
(setq js2-ts-hit-eof t
js2-ts-cursor (1+ js2-ts-cursor)
- c js2-EOF_CHAR) ; return value
+ c js2-EOF_CHAR) ; return value
;; otherwise read next char
(setq c (char-before (cl-incf js2-ts-cursor)))
;; if we read a newline, update counters
- (if (= c ?\n)
+ (if (memq c js2-eol-chars)
(setq js2-ts-line-start js2-ts-cursor
js2-ts-lineno (1+ js2-ts-lineno)))
;; TODO: skip over format characters
@@ -5670,7 +5671,7 @@ See http://es5.github.io/#x7.6"
;; TODO: change this nil to check for Unicode space character
nil)))
-(defconst js2-eol-chars (list js2-EOF_CHAR ?\n ?\r))
+(defconst js2-eol-chars (list js2-EOF_CHAR ?\n ?\r ?\u2028 ?\u2029))
(defun js2-skip-line ()
"Skip to end of line."
These details aside, do you expect to be using this distinction? Is there JS code in the wild relying on this?
from js2-mode.
Thanks!
These details aside, do you expect to be using this distinction? Is there JS code in the wild relying on this?
No, I don't expect to write any such code myself — it's more of a security thing.
from js2-mode.
All right.
Then should we go for a more obvious warning via font-lock rather than parsing the code in a different way? This could be done in both js-mode and js2-mode fairly easily: just highlight every such line from the encountered character until eol with the warning face or something.
from js2-mode.
Then should we go for a more obvious warning via font-lock rather than parsing the code in a different way?
That would be a reasonably good workaround, I think.
from js2-mode.
Considering this class of attacks exists in a bunch of languages, maybe it would be a good idea to report this sort of thing upstream so it can be handled in a consistent way across major modes?
from js2-mode.
maybe it would be a good idea to report this sort of thing upstream so it can be handled in a consistent way across major modes?
That could be a good addition to the original report, yes.
from js2-mode.
Related Issues (20)
- Syntax highlighting only applied after edit HOT 20
- Omitting parentheses and identifiers of CATCH should not raise errors HOT 1
- forward-sexp and backward-sexp are incoherent HOT 1
- Imenu support for mocha-like test files HOT 8
- private method and private property are not indenting HOT 2
- How to disable syntax highlight. HOT 2
- Make "Code has no side effects" warning optional HOT 2
- HTML tag regex inadvertently matches types. HOT 2
- js2-PRIVATE_NAME is breaking js2-skip-preprocessor-directives HOT 7
- No code highlighting without menu-bar? HOT 6
- Using '#' pound sign for 'private' properties in a .js file causes syntax issues to not be highlighted HOT 6
- Possible bug with js2-node-abs-pos and `new` expressions HOT 3
- Escaped expressions containing a real expression in a template literal inside a a lambda inside a class method break the parser HOT 2
- Static blocks not recognised as valid code HOT 2
- Does js2-mode become obsolete in Emacs 27.1? Or that the latest stable is not available via ELPA / MELPA? HOT 1
- Update README.md to explain the differences (incl. benefits and caveats) of `js2-mode` versus other packages HOT 11
- js2-mode does not recognize asynchronous generators within class or object HOT 3
- New static initialization blocks support has problems with named IIFE and 'use strict' HOT 4
- Feature request: insert closing delimiter HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from js2-mode.