Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Invalid regular expression: /\/: \ at end of pattern #4

Closed
thalesmello opened this issue Jan 28, 2020 · 2 comments
Closed

[BUG] Invalid regular expression: /\/: \ at end of pattern #4

thalesmello opened this issue Jan 28, 2020 · 2 comments

Comments

@thalesmello
Copy link

Describe the bug

An exception is thrown when you try to use '' as quote character.

To Reproduce
Steps to reproduce the behavior:

  1. Issued pxi command.
printf '{"a":1,"b":[1,2,3]}\n{"a":2,"b":{"c":2}}' | pxi --to csv --no-fixed-length --allow-list-values --quote '\'
  1. Error thrown or unexpected behavior.
/Users/thales/.nodenv/versions/11.9.0/lib/node_modules/pxi/node_modules/pxi-dsv/src/serializers/dsv.js:59
    const regexpQuote = new RegExp(_quote, 'g')
                        ^

SyntaxError: Invalid regular expression: /\/: \ at end of pattern
    at new RegExp (<anonymous>)
    at argv (/Users/thales/.nodenv/versions/11.9.0/lib/node_modules/pxi/node_modules/pxi-dsv/src/serializers/dsv.js:59:25)
    at func (/Users/thales/.nodenv/versions/11.9.0/lib/node_modules/pxi/node_modules/pxi-dsv/src/serializers/csv.js:23:7)
    at Object.initFunctions (/Users/thales/.nodenv/versions/11.9.0/lib/node_modules/pxi/src/api.js:36:96)
    at Object.<anonymous> (/Users/thales/.nodenv/versions/11.9.0/lib/node_modules/pxi/index.js:19:27)
    at Module._compile (internal/modules/cjs/loader.js:734:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:745:10)
    at Module.load (internal/modules/cjs/loader.js:626:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:566:12)
    at Function.Module._load (internal/modules/cjs/loader.js:558:3)

Expected behavior

Either make it work with a backspace character or treat the exception to make it more user-friendly, like "Unfortunately \ is not supported as quoting character".

I actually found this bug by mistake, as I misplaced the escape for the quote parameter.

@Yord
Copy link
Owner

Yord commented Jan 28, 2020

Hi thalesmello,

nice catch! Thanks to your detailed description, this should be an easy fix. I am currently looking into either removing the regular expression altogether or coming up with a better error, as you suggested.

Cheers
Yord

@Yord
Copy link
Owner

Yord commented Jan 30, 2020

I fixed the issue in pxi-dsv version 0.9.2 that was included in pxi version 0.36.10.

The fix was replacing the regular expression by while-looping over indexOf(quote). The backslash was also added to the quote and escape arbitraries in the tests.

The command you reported and similar commands should work from pxi --version 0.36.10 going forward.

I close the issue for now. Should the issue or a similar issue persist, I will reopen it.

@Yord Yord closed this as completed Jan 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants