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

Paths with special characters incorrectly treated as regular expressions rather than fixed strings #69

Closed
kitebuggy opened this issue Dec 3, 2022 · 3 comments · Fixed by #70

Comments

@kitebuggy
Copy link

kitebuggy commented Dec 3, 2022

Issue stems from the self.locale_prefix_from method in nice_partials.rb:

root_paths.each { |path| partial_location.gsub!(/^#{path}\//, '') }

Can be resolved by simply using Regexp.escape, as follows:

root_paths.each { |path| partial_location.gsub!(/^#{Regexp.escape(path)}\//, '') }

Seems too simple for a proper PR, hope this works instead?

@kaspth
Copy link
Contributor

kaspth commented Dec 7, 2022

I don't know how to write a regression test for this. Can you send a PR? Or give a full example that fails?

@kaspth
Copy link
Contributor

kaspth commented Dec 7, 2022

A potential alternative could also be partial_location.delete_prefix!(path), which is simpler even without this bug.

@kitebuggy
Copy link
Author

Absolutely - my apologies for not explaining in the first instance. Due to having both a work and personal Dropbox account, the path in question (on macOS) begins: /Users/kitebuggy/Dropbox (Company)/Dev/bullet_train/...

Any path with brackets like these (or any other characters with special meaning in RegEx) will result in the failure of this call unless it is escaped, as gsub will assume that path is a Regexp and not a fixed string.

I agree that partial_location.delete_prefix!(path) would also work, is prettier, and should save a CPU cycle or six too.

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 a pull request may close this issue.

2 participants