Skip to content

Escape all strings#5

Open
ups91 wants to merge 1 commit intoandyyaldoo:masterfrom
ups91:patch-1
Open

Escape all strings#5
ups91 wants to merge 1 commit intoandyyaldoo:masterfrom
ups91:patch-1

Conversation

@ups91
Copy link

@ups91 ups91 commented Jan 24, 2019

This patch allow us escape not only valid json string, but any (selected) text.

This patch allow us escape not only valid json string, but any (selected) text.
@ghost
Copy link

ghost commented Apr 9, 2019

Would you mind giving examples? Wouldn't it be better to make sure it's a valid JSON? It's a JSON tool after all :)

@taichunmin
Copy link

In my opinion, the isValid function should be change to:

public isValid(text: string): boolean {
  try {
    JSON.parse(text);
    return true;
  } catch (err) {
    return false;
  }
}

Because JSON can also be number, string, boolean or null.

@taichunmin
Copy link

taichunmin commented Jan 31, 2020

For example, some programing language (like PHP) or IE will escape non-utf8 charset by default:

<?php
$a = "測試";
echo json_encode($a);

// "\u6e2c\u8a66"

If we can change the isValid function, then this string is also be supported.

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 this pull request may close these issues.

2 participants