Skip to content

Commit

Permalink
fix(core): replace unicode with UTF-8 character
Browse files Browse the repository at this point in the history
Replace escaped unicode occurrences in text with their respective UTF-8
character. This enables the use of non-ASCII characters in the project
path.

Closes nestjs#1868
  • Loading branch information
Hannes-Kunnen committed Dec 6, 2023
1 parent 546f7a8 commit 487e3c0
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/plugin/utils/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,17 @@ export function getText(
typeFormatFlags = getDefaultTypeFormatFlags(enclosingNode);
}
const compilerNode = !enclosingNode ? undefined : enclosingNode;
return typeChecker.typeToString(type, compilerNode, typeFormatFlags);

const text = typeChecker.typeToString(type, compilerNode, typeFormatFlags);

// Regex to match escaped unicode
const unicodeRegex = /\\u([\dA-Fa-f]{4})/g

// Replace all escaped unicode occurrences with respective UTF-8 character
return text.replace(unicodeRegex, (match, unicode) => {
const charCode = parseInt(unicode, 16);
return String.fromCharCode(charCode);
});
}

export function getDefaultTypeFormatFlags(enclosingNode: Node) {
Expand Down

0 comments on commit 487e3c0

Please sign in to comment.