Skip to content

Commit 7cae738

Browse files
committed
Improved keyword matching
Updated keyword regex to support repeated keywords
1 parent fb10c78 commit 7cae738

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ const DEFAULT_OPTIONS = {
1616
}
1717
const clearStyle = '\x1b[0m'
1818

19-
const SPLIT_CHARS = '(^|[^a-zA-Z_])'
19+
const SPLIT_CHARS = '[^a-zA-Z_]'
2020

2121
const highlighters = [
2222
{
2323
name: 'keyword',
24-
regex: new RegExp(`${SPLIT_CHARS}(?:${keywords.join('|')})${SPLIT_CHARS}`, 'g')
24+
regex: new RegExp(`(?:^|${SPLIT_CHARS})(?:${keywords.join('|')})(?=${SPLIT_CHARS})`, 'g')
2525
},
2626
{
2727
name: 'special',

test/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ const { highlight } = require('../index')
77

88
console.log(highlight("SELECT COUNT(id), COUNT(id), `id`, `username` FROM `users` WHERE `email` = '[email protected]' AND `something` = 'oke' AND 1=1"))
99
console.log(highlight('SELECT "users".* FROM "users"'))
10+
console.log(highlight(`select "users".* from "users" where ("username" = 'test' or "email" = 'test') and "is_admin" = true and "is_banned" = false limit 1`))

0 commit comments

Comments
 (0)