Skip to content

Commit

Permalink
Fix errors for semicolons within quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarhane committed May 23, 2017
1 parent d24126b commit 42067f3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/shared/services/commandUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,19 @@ export const getInterpreter = (interpret, cmd, cmdchar) => {
export const isNamedInterpreter = (interpreter) => interpreter && interpreter.name !== 'catch-all'

export const extractPostConnectCommandsFromServerConfig = (str) => {
const substituteStr = '@@semicolon@@'
const substituteRe = new RegExp(substituteStr, 'g')
const replaceFn = (m) => m.replace(/;/g, substituteStr)
const qs = [
/(`[^`]*?`)/g,
/("[^"]*?")/g,
/('[^']*?')/g
]
qs.forEach((q) => (str = str.replace(q, replaceFn)))
const splitted = str
.split(';')
.map((item) => item.trim())
.map((item) => item.replace(substituteRe, ';'))
.filter((item) => item && item.length)
return splitted && splitted.length ? splitted : undefined
}
7 changes: 6 additions & 1 deletion src/shared/services/commandUtils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ describe('commandutils', () => {
{ str: ':play cypher ;', expect: [':play cypher'] },
{ str: ';:play cypher;', expect: [':play cypher'] },
{ str: ':play cypher; :param x: 1', expect: [':play cypher', ':param x: 1'] },
{ str: 'RETURN 1; RETURN 3; :play start', expect: ['RETURN 1', 'RETURN 3', ':play start'] }
{ str: 'RETURN 1; RETURN 3; :play start', expect: ['RETURN 1', 'RETURN 3', ':play start'] },
{ str: 'MATCH (n: {foo: "bar;", bar: "foo;"}) RETURN n', expect: ['MATCH (n: {foo: "bar;", bar: "foo;"}) RETURN n'] },
{ str: 'MATCH (n: {foo: \'bar;\'}) RETURN n', expect: ['MATCH (n: {foo: \'bar;\'}) RETURN n'] },
{ str: 'MATCH (n: {foo: `bar;`}) RETURN n', expect: ['MATCH (n: {foo: `bar;`}) RETURN n'] },
{ str: 'MATCH (n: {foo: `bar;;`}) RETURN n', expect: ['MATCH (n: {foo: `bar;;`}) RETURN n'] },
{ str: ':play cypher; MATCH (n: {foo: `bar; en;`}) RETURN n', expect: [':play cypher', 'MATCH (n: {foo: `bar; en;`}) RETURN n'] }
]

// When & Then
Expand Down

0 comments on commit 42067f3

Please sign in to comment.