-
-
Notifications
You must be signed in to change notification settings - Fork 601
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
fix: avoid all escaped characters replaced #917
fix: avoid all escaped characters replaced #917
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good solution, but i thanks we should avoid this for all escaped characters, not only for @
Ok. I'll think about the solution and make changes. |
Added solution for escaped characters, but i haven't won ascii hex escaped numeric The code below does not work correctly. function normalizeIdentifier(value) {
const escapedSymbolsMap = {
'\\7E': '~',
'': '!',
'\\40': '@',
'\\23': '#',
'\\24': '$',
'\\25': '%',
'\\26': '&',
'\\5E': '^',
'': '*',
'': '(',
'': ')',
'\\7B': '{',
'\\7D': '}',
'\\5B': '[',
'\\5D': ']',
'\\60': '`',
'\\2F': '/',
'\\3D': '=',
'\\3F': '?',
'': '+',
'\\5C': '\\',
'\\7C': '|',
'': '-',
'': '_',
'\\3A': ':',
'\\3B': ';',
'': '\'',
'': '"',
'': ',',
'\\3C': '<',
'': '.',
'\\5C': '>'
};
const escapedSymbols = Object.values(escapedSymbolsMap);
const escapedSymbolsCode = Object.keys(escapedSymbolsMap).filter(item => item !== '');
const identifiersRegExp = new RegExp(
`[^a-zA-Z0-9${escapedSymbols.join('\\')}\\-_\u00A0-\uFFFF]`,
'g'
);
escapedSymbolsCode.forEach(code => {
const regExp = new RegExp(code, 'g');
value = value.replace(regExp, escapedSymbolsMap[code]);
});
return value
.replace(identifiersRegExp, '-')
.replace(/^((-?[0-9])|--)/, '_$1');
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good, thanks! Just one note and we can merge
Done |
Thanks for PR |
This PR contains a:
Motivation / Use-Case
fixes #913
Breaking Changes
No
Additional Info
No