2121 * This rule is based on the JSON grammar from RFC 8259, section 6.
2222 * https://tools.ietf.org/html/rfc8259#section-6
2323 *
24+ * Also, this rule is based on the JSON5 grammar from json5.org, section 6.
25+ * https://spec.json5.org/#numbers
26+ *
2427 * We separately capture the integer and fractional parts of a number, so that
2528 * we can check for unsafe numbers that will evaluate to Infinity.
2629 */
27- const NUMBER = / ^ - ? (?< int > 0 | ( [ 1 - 9 ] \d * ) ) (?: \. (?< frac > \d + ) ) ? (?: e [ + - ] ? \d + ) ? $ / iu;
30+ const NUMBER =
31+ / ^ [ + - ] ? (?< int > 0 | ( [ 1 - 9 ] \d * ) ) ? (?: \. (?< frac > \d * ) ) ? (?: e [ + - ] ? \d + ) ? $ / iu;
2832const NON_ZERO = / [ 1 - 9 ] / u;
2933
3034//-----------------------------------------------------------------------------
@@ -71,7 +75,10 @@ const rule = {
7175 // fraction or non-zero part before the e-, this is a very small
7276 // number that doesn't fit inside an f64.
7377 const match = value . match ( NUMBER ) ;
74- // assert(match, "If the regex is right, match is always truthy")
78+
79+ if ( match === null ) {
80+ return ;
81+ }
7582
7683 // If any part of the number other than the exponent has a
7784 // non-zero digit in it, this number was not intended to be
@@ -99,7 +106,7 @@ const rule = {
99106 } ) ;
100107 }
101108 } else {
102- // Floating point. Check for subnormal.
109+ // Floating point. Check for subnormal.
103110 const buffer = new ArrayBuffer ( 8 ) ;
104111 const view = new DataView ( buffer ) ;
105112 view . setFloat64 ( 0 , node . value , false ) ;
@@ -128,8 +135,11 @@ const rule = {
128135 // match any low surrogate not already matched
129136 const surrogatePattern =
130137 / [ \uD800 - \uDBFF ] [ \uDC00 - \uDFFF ] ? | [ \uDC00 - \uDFFF ] / gu;
131- let match = surrogatePattern . exec ( node . value ) ;
132- while ( match ) {
138+
139+ /** @type {RegExpExecArray | null } */
140+ let match ;
141+
142+ while ( ( match = surrogatePattern . exec ( node . value ) ) !== null ) {
133143 // only need to report non-paired surrogates
134144 if ( match [ 0 ] . length < 2 ) {
135145 context . report ( {
@@ -143,7 +153,6 @@ const rule = {
143153 } ,
144154 } ) ;
145155 }
146- match = surrogatePattern . exec ( node . value ) ;
147156 }
148157 } ,
149158 } ;
0 commit comments