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

Escape vertical tab #31

Open
tschechniker opened this issue Feb 2, 2021 · 4 comments · May be fixed by #33
Open

Escape vertical tab #31

tschechniker opened this issue Feb 2, 2021 · 4 comments · May be fixed by #33

Comments

@tschechniker
Copy link

Hi,

just came over this issue. If you have a string including a vertical tab the json is broken. We need to escape it. Could you please extend the escaping list and add "\v" to be escaped too?

Thanks!

Tobi

@tschechniker
Copy link
Author

something like this helps:

yieldable-stringify.js

 let escape = {
    '\b': '\\b',
    '\t': '\\t',
    '\n': '\\n',
    '\f': '\\f',
    '\r': '\\r',
    '\v': '\\u000B',
    '"': '\\"',
  };

@gireeshpunathil
Copy link
Member

@tschechniker - thanks for reporting this, I will look at this.

yathamravali pushed a commit to yathamravali/yieldable-json that referenced this issue Dec 20, 2021
by adding escape sequencing for vertical tab

Add two unit tests to validate this scenario.
Fixes: ibmruntimes#31
yathamravali pushed a commit to yathamravali/yieldable-json that referenced this issue Dec 20, 2021
Both APIs fail when the key or value contain vertical tab. Fix that
by adding escape sequencing for vertical tab

Add two unit tests to validate this scenario.
Fixes: ibmruntimes#31
@yathamravali yathamravali linked a pull request Dec 20, 2021 that will close this issue
@daniele-pini
Copy link

daniele-pini commented Oct 3, 2024

Hello, I have the same problem with characters \u0000 to \u0019.

Unfortunately, I acquire strings from a 3rd party source that I need to parse, modify and re-stringify, so I also wonder if there are other possible cases, too?

To clarify, in this example:

const yj = require('yieldable-json');

const obj = { value: '\u0000' };

const str1 = JSON.stringify(obj);
console.log('str1: ' + str1);

yj.stringifyAsync(obj, (err, str2) => {
  console.log('str2: ' + (str2));
  const parsed = JSON.parse(str2);
  console.log(parsed);
});

I get:

str1: {"value":"\u0019"}
str2: {"value":""}
undefined:1
{"value":""}
          ^

SyntaxError: Bad control character in string literal in JSON at position 10
    at JSON.parse (<anonymous>)
    at /home/puppy/work/test/index.js:11:23
    at Immediate.<anonymous> (/home/puppy/work/test/node_modules/yieldable-json/yieldable-stringify.js:276:18)
    at process.processImmediate (node:internal/timers:483:21)

@5d-jh
Copy link

5d-jh commented Dec 24, 2024

I'm also encountering this issue, whicih is making it unable to parse json. I would appreciate if this PR could be merged.

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

Successfully merging a pull request may close this issue.

4 participants