Skip to content

Commit

Permalink
fixes #2224: various issues related to number lexing
Browse files Browse the repository at this point in the history
This was... embarrassing. I'm just really glad we didn't cut a release
before this got fixed.
  • Loading branch information
michaelficarra committed Mar 28, 2012
1 parent ddd6e9a commit 6a88ce7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
10 changes: 5 additions & 5 deletions lib/coffee-script/lexer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/lexer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ exports.Lexer = class Lexer
numberToken: ->
return 0 unless match = NUMBER.exec @chunk
number = match[0]
if /E/.test number
@error "exponential notation '#{number}' must be indicated with a lowercase 'e'"
else if /[BOX]/.test number
if /^0[BOX]/.test number
@error "radix prefix '#{number}' must be lowercase"
else if /^0[89]/.test number
else if /E/.test(number) and not /^0x/.test number
@error "exponential notation '#{number}' must be indicated with a lowercase 'e'"
else if /^0\d*[89]/.test number
@error "decimal literal '#{number}' must not be prefixed with '0'"
else if /^0[0-7]/.test number
else if /^0\d+/.test number
@error "octal literal '#{number}' must be prefixed with '0o'"
lexedLength = number.length
if octalLiteral = /0o([0-7]+)/.exec number
Expand Down
5 changes: 5 additions & 0 deletions test/numbers.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,8 @@ test "#2060: Disallow uppercase radix prefixes and exponential notation", ->
program = "0#{char}0"
doesNotThrow -> CoffeeScript.compile program, bare: yes
throws -> CoffeeScript.compile program.toUpperCase(), bare: yes

test "#2224: hex literals with 0b or B or E", ->
eq 176, 0x0b0
eq 177, 0x0B1
eq 225, 0xE1

2 comments on commit 6a88ce7

@satyr
Copy link
Collaborator

@satyr satyr commented on 6a88ce7 Mar 28, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

glad we didn't cut a release before this got fixed

We did.

$ bin/coffee -v
CoffeeScript version 1.1.3

$ bin/coffee -bce '0x0b0'
0;

@michaelficarra
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. I was referring to the upcoming 1.3.0 (see #2135). It should have been "another" or "a new". This'll be getting in right before the upcoming release instead of right after it, which is way more desirable.

Please sign in to comment.