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.
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 madeIf doing the nested
gsub
, these two return values will be passed into the outergsub
, which accepts an optional fourth parameter specifying how many substitutions should be made. So the number of substitutions in the innergsub
determines the number of substitutions in the outergsub
: When the query doesn't contain a blank, that number of substitutions in the innergsub
is0
and the outergsub
won't replace anything, leaving${query}
in theurl
.By first assigning the
gsub
result to a variable, the number of substitutions return value will be ignored.