[Rpm-maint] [rpm-software-management/rpm] Any way to work around %gsub's (Lua-originating) escaping requirements regarding the input string? (Discussion #3826)
Frank Dana
notifications at github.com
Sat Jun 21 05:16:26 UTC 2025
**#TIL**, while trying to write a `%{gsub}` call to manipulate a package `%{version}`, that `%{gsub}` won't properly handle periods unless they're escaped not only in the pattern arguments, but also in the _source string_!
That restriction appears to come from Lua itself:
```lua
> string.gsub("1.2.3", ".", "_")
_____ 5
> string.gsub("1.2.3", "\\.", "_")
1.2.3 0
> string.gsub("1\\.2\\.3", "\\.", "_")
1_2_3 2
```
But it most certainly carries over to RPM:
```console
$ rpm --eval '%{gsub 1.2.3 . _}'
_____
$ rpm --eval '%{gsub 1.2.3 \\. _}'
1.2.3
$ rpm --eval '%{gsub 1\\.2\\.3 \\. _}'
1_2_3
```
That obviously becomes a problem when trying to `%{gsub %{version} ...)` because while escaping the patterns is no problem, unless I'm missing something obvious there's no way to easily escape any of the dots contained in `%{version}`. (We sure can't use `%{gsub}` to do it!)
It almost feels like we need a `%{regexscape:}` or `${patescape:}` to go with `%{quote:}` and `%{shescape:}`, because neither of those will DTRT here, either.
--
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/discussions/3826
You are receiving this because you are subscribed to this thread.
Message ID: <rpm-software-management/rpm/repo-discussions/3826 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20250620/eb4a08e0/attachment.htm>
More information about the Rpm-maint
mailing list