Skip to content

Commit 6047fba

Browse files
committed
feat(tokens): Ignore JWTs
Fixes #1057
1 parent 5eab324 commit 6047fba

File tree

1 file changed

+36
-40
lines changed

1 file changed

+36
-40
lines changed

crates/typos/src/tokens.rs

+36-40
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ mod parser {
191191
terminated(email_literal, peek(sep1)),
192192
terminated(url_literal, peek(sep1)),
193193
terminated(css_color, peek(sep1)),
194+
terminated(jwt, peek(sep1)),
194195
c_escape,
195196
printf,
196197
other,
@@ -297,6 +298,41 @@ mod parser {
297298
.parse_next(input)
298299
}
299300

301+
fn jwt<T>(input: &mut T) -> PResult<<T as Stream>::Slice, ()>
302+
where
303+
T: Compare<char>,
304+
T: Stream + StreamIsPartial + PartialEq,
305+
<T as Stream>::Slice: AsBStr + SliceLen + Default,
306+
<T as Stream>::Token: AsChar + Copy,
307+
{
308+
trace(
309+
"jwt",
310+
(
311+
'e',
312+
'y',
313+
take_while(20.., is_jwt_token),
314+
'.',
315+
'e',
316+
'y',
317+
take_while(20.., is_jwt_token),
318+
'.',
319+
take_while(20.., is_jwt_token),
320+
)
321+
.recognize(),
322+
)
323+
.parse_next(input)
324+
}
325+
326+
#[inline]
327+
fn is_jwt_token(i: impl AsChar + Copy) -> bool {
328+
let c = i.as_char();
329+
c.is_ascii_lowercase()
330+
|| c.is_ascii_uppercase()
331+
|| c.is_ascii_digit()
332+
|| c == '_'
333+
|| c == '-'
334+
}
335+
300336
fn uuid_literal<T>(input: &mut T) -> PResult<<T as Stream>::Slice, ()>
301337
where
302338
T: Compare<char>,
@@ -1582,26 +1618,6 @@ mod test {
15821618
case: None,
15831619
offset: 23,
15841620
},
1585-
Identifier {
1586-
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9",
1587-
case: None,
1588-
offset: 30,
1589-
},
1590-
Identifier {
1591-
token: "eyJpc3MiOiJzdXBhYmFzZSIsInJvbGUiOiJhbm9uIiwiaWF0IjoxNjQ1MTkyODI0LCJleHAiOjE5NjA3Njg4MjR9",
1592-
case: None,
1593-
offset: 67,
1594-
},
1595-
Identifier {
1596-
token: "M9jrxyvPLkUxWgOYSf5dNdJ8v_eRrq810ShFRT8N",
1597-
case: None,
1598-
offset: 156,
1599-
},
1600-
Identifier {
1601-
token: "6M",
1602-
case: None,
1603-
offset: 197,
1604-
},
16051621
]
16061622
16071623
"#]]
@@ -1626,26 +1642,6 @@ mod test {
16261642
case: None,
16271643
offset: 23,
16281644
},
1629-
Identifier {
1630-
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9",
1631-
case: None,
1632-
offset: 30,
1633-
},
1634-
Identifier {
1635-
token: "eyJpc3MiOiJzdXBhYmFzZSIsInJvbGUiOiJhbm9uIiwiaWF0IjoxNjQ1MTkyODI0LCJleHAiOjE5NjA3Njg4MjR9",
1636-
case: None,
1637-
offset: 67,
1638-
},
1639-
Identifier {
1640-
token: "M9jrxyvPLkUxWgOYSf5dNdJ8v_eRrq810ShFRT8N",
1641-
case: None,
1642-
offset: 156,
1643-
},
1644-
Identifier {
1645-
token: "6M",
1646-
case: None,
1647-
offset: 197,
1648-
},
16491645
]
16501646
16511647
"#]]

0 commit comments

Comments
 (0)