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

Add single quote support in importmap.rb #198

Merged
merged 3 commits into from
Oct 27, 2023

Conversation

vietqhoang
Copy link
Contributor

@vietqhoang vietqhoang commented Sep 18, 2023

Related issue: #156

Problem

Wrapping strings with single-quotes in the importmap.rb file is not picked up by commands audit and outdated.

Expectation

The audit and outdated commands should pick up pins where either double or single quotes are used.

Solution

The problematic lines are the following:

The regex are designed to only scan for double-quotes. The proposed change adds in detection for double-quotes and single-quotes.

The implementation proposed is a bit naive in that strings wrapped with one double-quote and one single-quote will return positive. For example, pin "local_time' #@2.1.0 will return positive. Running outdated and audit will run without issue. On a Rails app using importmap, the SyntaxError: unterminated string meets end of file will raise.

Whether or not it is important to address this quirk is up for discussion.

Below are how example pins (taken from issue #156 and test fixtures) fair against the updated regexes.

Added a test case for the more compact version of the pin, where the CDN url is not used.
The failed tests are now passing.

The approach is a little naive in that a string surrounded by one double quote and one single quote will return as a positive result.

Whether this is important enough that it should be addressed with a more complex regex is up for question.
The OR seperator is not used appropriately (and not needed) in character group.
@rafaelfranca rafaelfranca merged commit 9fac238 into rails:main Oct 27, 2023
12 checks passed
@vietqhoang vietqhoang deleted the add-single-quote-support branch October 27, 2023 17:20
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.

2 participants