Skip to content

Commit 1683383

Browse files
authored
Fixes issue #6 (#15)
* fix issue with sqlString getting cut off at the end * whitespace changes for eslint * remove console.log * Increase code coverage back up to 100% * ESlint wants single quotes * So, these are the real tests apparently
1 parent f565c62 commit 1683383

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ function highlight (sqlString, options) {
9494
highlighted += stringMatch
9595
highlighted += options.colors.clear
9696
}
97-
9897
if (nextMatch) {
9998
highlighted += sqlString.substr(match.start + match.length, nextMatch.start - (match.start + match.length))
99+
} else if (sqlString.length > (match.start + match.length)) {
100+
highlighted += sqlString.substr(match.start + match.length)
100101
}
101102
}
102103

index.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,9 @@ describe('html', () => {
131131
expect(hlHtml("SELECT COUNT(id), `id`, `username` FROM `users` WHERE `email` = '[email protected]' AND `foo` = 'BAR' OR 1=1"))
132132
.toBe("<span class=\"sql-hl-keyword\">SELECT</span> <span class=\"sql-hl-function\">COUNT</span><span class=\"sql-hl-bracket\">(</span>id<span class=\"sql-hl-bracket\">)</span><span class=\"sql-hl-special\">,</span> <span class=\"sql-hl-string\">`id`</span><span class=\"sql-hl-special\">,</span> <span class=\"sql-hl-string\">`username`</span><span class=\"sql-hl-keyword\"> FROM</span> <span class=\"sql-hl-string\">`users`</span><span class=\"sql-hl-keyword\"> WHERE</span> <span class=\"sql-hl-string\">`email`</span> <span class=\"sql-hl-special\">=</span> <span class=\"sql-hl-string\">'[email protected]'</span><span class=\"sql-hl-keyword\"> AND</span> <span class=\"sql-hl-string\">`foo`</span> <span class=\"sql-hl-special\">=</span> <span class=\"sql-hl-string\">'BAR'</span><span class=\"sql-hl-keyword\"> OR</span> <span class=\"sql-hl-number\">1</span><span class=\"sql-hl-special\">=</span><span class=\"sql-hl-number\">1</span>")
133133
})
134+
135+
it('query with identifiers without apostrophes', () => {
136+
expect(hlHtml('SELECT id FROM users'))
137+
.toBe('<span class="sql-hl-keyword">SELECT</span> id<span class="sql-hl-keyword"> FROM</span> users')
138+
})
134139
})

test/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ console.log(highlight('select "users".* from "users" where ("username" = \'test\
1111

1212
console.log(highlight("SELECT COUNT(id), COUNT(id), `id`, `username` FROM `users` WHERE `email` = '[email protected]' AND `something` = 'oke-doke' AND true = true"))
1313
console.log(highlight("SELECT COUNT(id), `id`, `username` FROM `users` WHERE `email` = '[email protected]' AND (username in ( SELECT \"name\" from aTable)", { html: false }))
14+
console.log(highlight('SELECT id FROM users'))

0 commit comments

Comments
 (0)