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 query replacement for non-spaced queries #272

Merged
merged 1 commit into from
Feb 27, 2023

Conversation

thomasjachmann
Copy link
Contributor

Bug

When querying a single word (without spaces), the substitution string ${query} won't be replaced.

Explanation/Fix

string.gsub returns two values: the string with substitutions and the number of substitutions made

If doing the nested gsub, these two return values will be passed into the outer gsub, which accepts an optional fourth parameter specifying how many substitutions should be made. So the number of substitutions in the inner gsub determines the number of substitutions in the outer gsub: When the query doesn't contain a blank, that number of substitutions in the inner gsub is 0 and the outer gsub won't replace anything, leaving ${query} in the url.

By first assigning the gsub result to a variable, the number of substitutions return value will be ignored.

`string.gsub` returns two values: the string with substitutions and the number of substitutions made

If doing the nested `gsub`, these two return values will be passed into the outer `gsub`, which accepts an optional fourth parameter specifying how many substitutions should be made. So the number of substitutions in the inner `gsub` determines the number of substitutions in the outer `gsub`: When the query doesn't contain a blank, that number of substitutions in the inner `gsub` is `0` and the outer `gsub` won't replace anything, leaving '${query}' in the `url`.
@dxmh
Copy link

dxmh commented Dec 6, 2022

This PR fixes the issue in #284 for me. 👍

@cmsj cmsj merged commit 4171e77 into Hammerspoon:master Feb 27, 2023
@cmsj
Copy link
Member

cmsj commented Feb 27, 2023

Thanks, and apologies for taking a while to get to this.

eraserhd pushed a commit to eraserhd/Spoons that referenced this pull request Jul 11, 2024
`string.gsub` returns two values: the string with substitutions and the number of substitutions made

If doing the nested `gsub`, these two return values will be passed into the outer `gsub`, which accepts an optional fourth parameter specifying how many substitutions should be made. So the number of substitutions in the inner `gsub` determines the number of substitutions in the outer `gsub`: When the query doesn't contain a blank, that number of substitutions in the inner `gsub` is `0` and the outer `gsub` won't replace anything, leaving '${query}' in the `url`.
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.

3 participants