Skip to content

Commit

Permalink
Merge d189de1 into 0b6765b
Browse files Browse the repository at this point in the history
  • Loading branch information
erikn69 committed Jul 25, 2022
2 parents 0b6765b + d189de1 commit d354f0e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
20 changes: 20 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ describe('unicode', () => {
.toBe('[string]"Hello, world!"[clear]')
})

it('strings (mixing quotes)', () => {
expect(hlUni('\'"`\' "\'`" `"\'`'))
.toBe('[string]\'"`\'[clear] [string]"\'`"[clear] [string]`"\'`[clear]')
})

it('strings (scaping quotes)', () => {
expect(hlUni('\'\\\'\' "\\"" `\\``'))
.toBe('[string]\'\\\'\'[clear] [string]"\\""[clear] [string]`\\``[clear]')
})

it('integers', () => {
expect(hlUni('42'))
.toBe('[number]42[clear]')
Expand Down Expand Up @@ -97,6 +107,16 @@ describe('html', () => {
.toBe('<span class="sql-hl-string">"Hello, world!"</span>')
})

it('strings (mixing quotes)', () => {
expect(hlHtml('\'"`\' "\'`" `"\'`'))
.toBe('<span class="sql-hl-string">\'"`\'</span> <span class="sql-hl-string">"\'`"</span> <span class="sql-hl-string">`"\'`</span>')
})

it('strings (scaping quotes)', () => {
expect(hlHtml('\'\\\'\' "\\"" `\\``'))
.toBe('<span class="sql-hl-string">\'\\\'\'</span> <span class="sql-hl-string">"\\""</span> <span class="sql-hl-string">`\\``</span>')
})

it('integers', () => {
expect(hlHtml('42'))
.toBe('<span class="sql-hl-number">42</span>')
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const highlighters = [
},
{
name: 'string',
regex: /(["'`].*?["'`])/g
regex: /(['](?:\\'|.)*?[']|["](?:\\"|.)*?["]|[`](?:\\`|.)*?[`])/g
},
{
name: 'bracket',
Expand Down
3 changes: 3 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ console.log(highlight('WITH t1 AS (SELECT data_point FROM tablename) SELECT data

console.log(highlight('SELECT id FROM listings WHERE status = \'not available\''))
console.log(highlight('SELECT id FROM listings WHERE status = "not available"'))

console.log(highlight('SELECT \'{"json_index":"json_value"}\' AS test;'))
console.log(highlight('SELECT \'3\\\' 5\\\'\\\'\\\' AS test;'))

0 comments on commit d354f0e

Please sign in to comment.