[Buildroot] [RFC PATCH 2/5] package/pkg-utils.mk: urlencode/urldecode macros
Thomas Perale
thomas.perale at essensium.com
Thu Apr 4 12:43:26 UTC 2024
This patch introduces two new macros:
- urlencode
- urldecode
URL encoding consists of converting ASCII characters into
a percent symbol followed by a two digit hexadecimal code.
And the other way around for URL decoding.
The macros encode/decode a string passed as an argument by
escaping the following characters:
- '%' is replaced by %25
- 'space' is replaced by %20
The characters covered by this patch is non exhaustive.
Because the Make language treats spaces as different entry of a list,
the aim of those macros is to provide a well known encoding method
to escape text containing spaces into a string that won't be
treated as a list by the Make language.
Signed-off-by: Thomas Perale <thomas.perale at mind.be>
---
package/pkg-utils.mk | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/package/pkg-utils.mk b/package/pkg-utils.mk
index 723bbe4e24..b8cfb85fca 100644
--- a/package/pkg-utils.mk
+++ b/package/pkg-utils.mk
@@ -329,3 +329,15 @@ define NXP_EXTRACT_HELPER
find $(@D)/$(basename $(notdir $(1))) -mindepth 1 -maxdepth 1 -exec mv {} $(@D) \;
rmdir $(@D)/$(basename $(notdir $(1)))
endef
+
+# urlencode -- returns an url encoded string.
+# - encode % into %25
+# - encode spaces into %20
+#
+# $(1): text
+urlencode = $(subst $(space),%20,$(subst %,%25,$(1)))
+
+# urldecode -- decode an url encoded string.
+#
+# $(1): text
+urldecode = $(subst %25,%,$(subst %20,$(space),$(1)))
--
2.44.0
More information about the buildroot
mailing list