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

fix(core): support non-ASCII characters in filename paths #2745

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Hannes-Kunnen
Copy link

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

If there is a non-ASCII character in the path of a dto file this will result in failure to normalize the path.

Example of a non-ASCII character in the project path (actual/expected):

- ./../../../../../../Priv/u00E9/forks/nestjs-swagger/test/plugin/fixtures/project/cats/dto/pagination-query.dto
+ ./cats/dto/pagination-query.dto

Example of a non-ASCII character in the dto folder (actual/expected):

- /home/user/Documents/projects/nestjs-swagger/test/plugin/fixtures/project/cats/dto/priv\u00E9/unicode.dto
+ ./cats/dto/privé/unicode.dto

This results in incorrect imports in the generated JavaScript.

Issue Number: Closes #1868

What is the new behavior?

The swagger plugin now supports Unicode characters in paths to dto files.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Unescape escaped unicode characters in file paths.
Filepaths returned from TypeScript have their non-ASCII characters
escaped.
See https://www.github.com/microsoft/TypeScript/issues/36174

This enables the use of non-ASCII characters in the project
path.

Closes nestjs#1868
const unicodeRegex = /\\u([\dA-Fa-f]{4})/g

// Unescape escaped unicode https://github.com/microsoft/TypeScript/issues/36174
return text.replace(unicodeRegex, (match, unicode) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm somewhat worried about the performance implications of this change. Are we sure we want to run this regex on every invocation of getText?

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.

"Module not found" run-time error, if the project directory name contains non-ASCII characters
2 participants