trivago / melody

Melody is a library for building JavaScript web applications.
https://melody.js.org
Apache License 2.0
215 stars 39 forks source link

Bugfix: Prevent Number tokens from ending in a dot "." #153

Closed twbartel closed 4 years ago

twbartel commented 4 years ago

Previously, the expression

{{ 1..5 }}

produced a MemberExpression with the object being 1 and the property being 5. The reason was that matchNumber() in Lexer.js, when encountering a . in a number, prepared to read a series of decimals. In this case, it did not encounter anything, aborted, and produced a Number token with the text 1., which is a valid JavaScript number, but not a valid number in Twig (try, for example, {{ 1. }} on https://twigfiddle.com/).

This PR fixes this bug by looking ahead one additional character, and only going into decimal detection when there is a digit after the ..