-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
Avoid linkifying trailing question mark #50
Conversation
Oh, looks like snapshot needs to be updated:
I guess the snapshot update will need to be done locally, since the AVA snapshot format is binary and I can't edit by hand in the GitHub PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The snapshots can be updated via npx ava -u
I think. One is needed for this PR
index.js
Outdated
let trailingDot = ''; | ||
if (href.endsWith('.')) { | ||
// The regex URL mistakenly includes punctuation (a period or question mark) at the end of the URL | ||
let punctuation = ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just use a regex to extract it here, like:
const punctuation = trailingPunctuationRegex.exec(href) ?? '';
if (punctuation) {
href = href.slice(0, -1);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: fregante <me@fregante.com>
@fregante Made the suggested change and updated the snapshot |
index.js
Outdated
let trailingDot = ''; | ||
if (href.endsWith('.')) { | ||
// The URL regex mistakenly includes punctuation (a period or question mark) at the end of the URL | ||
const punctuation = /[.?]$/.exec(href) ?? ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fregante I guess it needs to access the first array element with optional chaining (suggestion already committed)
const punctuation = /[.?]$/.exec(href) ?? ''; | |
const punctuation = /[.?]$/.exec(href)?.[0] ?? ''; |
Repl:
/[.?]$/.exec('asdf.')
> ['.', index: 4, input: 'asdf.', groups: undefined]
/[.?]$/.exec('asdf.').toString()
> '.'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh TIL actually not necessary!
(because of the .toString()
method on the .exec()
result)
Repl:
'asdf' + /[.?]$/.exec('asdf.')
> 'asdf.'
/[.?]$/.exec('asdf.').toString()
> '.'
I think it's probably still more expressive with the ?.[0]
But if preferred, we can rely on the .toString()
"magic" and I can revert this change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me as is. Let's wait for Sindre
Thanks for the review and merge! |
Addition to #49 for #26
cc @fregante