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

Replace filter: unescape backslashes #109

Open
djbe opened this issue Oct 13, 2018 · 7 comments
Open

Replace filter: unescape backslashes #109

djbe opened this issue Oct 13, 2018 · 7 comments

Comments

@djbe
Copy link
Member

djbe commented Oct 13, 2018

In a template, if I try:
value|replace:"\n","\\n"

The search and replace strings become "\\n" and "\\\\n" respectively. I think we should un-escape these backslashes, so that users correctly can search for newlines (for example). Or is this something that we should handle in Stencil itself?

@AliSoftware
Copy link
Contributor

Mmmh good question. Is it:

  • The job of the replace filter itself
  • The job of Stencil itself (which would allow to fix that issue for all tags, but might be a breaking change too)
  • The job of SwiftGenKit (during parsing of the YAML/JSON/PLIST files)?

@djbe
Copy link
Member Author

djbe commented Oct 13, 2018

Note: SGK correctly parses the files (the string value is as it should be, unchanged).

@AliSoftware
Copy link
Contributor

Yeah the parsing itself shouldn't be changed, but should we or should we not convert newlines to \n when we build the context from those parsed content, or is that the job for Stencil or the template, that's the real question 😉

@djbe
Copy link
Member Author

djbe commented Oct 13, 2018

Keep in mind that if we do that in SGK, those strings may be somewhere quite deep in some array/dictionary structure, and we'd need to check all strings. Seems quite the overhead on the context builder, where it's honestly an issue in Stencil(SwiftKit).

@djbe
Copy link
Member Author

djbe commented Oct 13, 2018

Note: we also have a contains filter where this applies as well.
Note 2: and hasPrefix and hasSuffix also.

@AliSoftware
Copy link
Contributor

Yeah which is why I'm starting to wonder if it shouldn't be Stencil's job to do that un-escape, instead of each filter individually…

@djbe
Copy link
Member Author

djbe commented Oct 13, 2018

Right, so the culprit would be this line:
https://github.com/stencilproject/Stencil/blob/521a599a60206b61b1ac76dd0f01d20f95d3d588/Sources/Variable.swift#L53

Anyone know what's the best way to unescape something like "\\n" or "\\u5404\\u500b\\u90fd" (we may as well do this for unicode sequences)?

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

No branches or pull requests

2 participants