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

Backslash not escaped by TransferState #1382

Closed
BlindDespair opened this issue Jun 1, 2021 · 2 comments · Fixed by #1567 or #1581
Closed

Backslash not escaped by TransferState #1382

BlindDespair opened this issue Jun 1, 2021 · 2 comments · Fixed by #1567 or #1581
Labels
bug Something isn't working

Comments

@BlindDespair
Copy link
Contributor

🐞 Bug report

Description

Having data like {"amount": "450\45g"} breaks the page when data is read from the TransferState script on JSON.parse(). It works great when it's received by the data.json though.

🔬 Minimal Reproduction

Pass {"amount": "450\45g"} to TransferState and load the page directly.

💻Your Environment

Angular Version:

Angular CLI: 11.2.4
Node: 14.16.0
OS: win32 x64

Angular: undefined
...
Ivy Workspace: Yes

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.1102.4 (cli-only)
@angular-devkit/core         11.2.4 (cli-only)
@angular-devkit/schematics   11.2.4 (cli-only)
@schematics/angular          11.2.4 (cli-only)
@schematics/update           0.1102.4 (cli-only)
typescript                   4.0.7

Scully Version:

"@scullyio/ng-lib": "^1.1.1",
"@scullyio/scully": "^1.1.1",

🔥 Exception or Error

JSON.parse fails on \4

@BlindDespair BlindDespair added the bug Something isn't working label Jun 1, 2021
@hunhavoc
Copy link

hunhavoc commented Sep 21, 2021

@SanderElias Can this be fixed by extending the special char escaping arrays? If yes, is that a safe approach?

I mean this list and it's escaped pair:

        '_~q~': "'",
        '_~b~': '`',
        '_~o~': '$',
        '_~s~': '/',
        '_~l~': '<',
        '_~g~': '>',
    };

If yes, I'm going to open a PR for it.

@SanderElias
Copy link
Contributor

SanderElias commented Oct 4, 2021

@hunhavoc That is what I tried initially, but it doesn't work. It needs a bit more. For testing, put a \ in the user-data in libs/scully/src/lib/testData/users-testdata.ts
Something like this would do the job:

  {
    id: 2,
    name: 'Ervin `Howell`',
    username: 'Anton\\ette',
    email: 'Shanna@melissa.tv',
    address: {
      street: 'Victor Plains',
      suite: 'Suite 879',
      city: 'Wisokyburgh',
      zipcode: '90566-7771',
      geo: {
        lat: '-43.9509',
        lng: '-34.4618',
      },
    },
    phone: '010-692-6593 x09125',
    website: 'anastasia.net',
    company: {
      name: 'Deckow-Crist',
      catchPhrase: 'Proactive \n```\nconsole.log("euhm")\n```\n didactic contingency',
      bs: 'synergize scalable supply-chains',
    },
  },

If you can find out a way to do that, and pass all the tests. I'm more than willing to merge a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants