Skip to content

Commit bc6cbd9

Browse files
committed
* updated sed escaping for mulle-template
1 parent 44c4542 commit bc6cbd9

11 files changed

+408
-352
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required (VERSION 3.13)
22

3-
project( mulle-bashfunctions VERSION 6.5.0 LANGUAGES NONE)
3+
project( mulle-bashfunctions VERSION 6.5.1 LANGUAGES NONE)
44

55

66
#

RELEASENOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### 6.5.1
2+
3+
* updated sed escaping for mulle-template
4+
15
## 6.5.0
26

37
* `r_make_tmp` file extension can be specified as .foo or foo, the first . will be removed

mulle-bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fi
151151
# this is "our" version
152152
# the actual loaded version may differ (and will change this variable)
153153
#
154-
MULLE_BASHFUNCTIONS_VERSION="6.5.0"
154+
MULLE_BASHFUNCTIONS_VERSION="6.5.1"
155155
MULLE_BASHFUNCTIONS_LIBEXEC_DIRNAME="libexec"
156156
MULLE_EXECUTABLE="$1"
157157

mulle-bashfunctions

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ Examples:
6464
Load "mulle-bashfunctions-all.sh" into the current interactive shell:
6565

6666
eval \`mulle-bashfunctions load all\`
67+
r_escaped_json '{ "url": "https://www.mulle-kybernetik.com" }'
68+
echo \$RVAL
6769

6870
Commands:
6971
apropos <f> : search for a function by keywords

src/mulle-bashfunctions-all-embed.sh

Lines changed: 55 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,7 +1896,10 @@ function r_escaped_sed_pattern()
18961896
s="${s//\*/\\*}"
18971897
s="${s//\./\\.}"
18981898
s="${s//\^/\\^}"
1899-
s="${s//$'\n'/\\$'\n'}" # assume
1899+
s="${s//$'\n'/\\$'\n'}"
1900+
s="${s//$'\t'/\\$'\t'}"
1901+
s="${s//$'\r'/\\$'\r'}"
1902+
s="${s//$'\f'/\\$'\f'}"
19001903

19011904
RVAL="$s"
19021905
}
@@ -1906,10 +1909,14 @@ function r_escaped_sed_replacement()
19061909
{
19071910
local s="$1"
19081911

1909-
s="${s//\\/\\\\}"
1910-
s="${s//\//\\/}"
1911-
s="${s//&/\\&}"
1912-
s="${s//$'\n'/\\$'\n'}"
1912+
s="${s//\\/\\\\}" # escape backslashes first
1913+
s="${s//\//\\/}" # escape forward slashes
1914+
s="${s//\'/\'\\\'\'}" # escape single quotes by closing and reopening the quote
1915+
s="${s//&/\\&}" # escape ampersands
1916+
s="${s//$'\t'/\\t}" # escape tabs returns
1917+
s="${s//$'\r'/\\r}" # escape crlf returns
1918+
s="${s//$'\n'/\\n}" # escape newlines returns
1919+
s="${s//$'\f'/\\f}" # escape form feeds returns
19131920

19141921
RVAL="$s"
19151922
}
@@ -1957,49 +1964,49 @@ function r_escaped_shell_string()
19571964

19581965
function r_escaped_json()
19591966
{
1960-
RVAL="${*//\\/\\\\}"
1961-
1962-
RVAL="${RVAL//\"/\\\"}"
1963-
1964-
RVAL="${RVAL//$'\n'/\\n}"
1965-
1966-
RVAL="${RVAL//$'\r'/\\r}"
1967-
1968-
RVAL="${RVAL//$'\t'/\\t}"
1969-
1970-
RVAL="${RVAL//$'\b'/\\b}"
1971-
1972-
RVAL="${RVAL//$'\f'/\\f}"
1973-
1974-
RVAL="${RVAL//\//\\/}"
1975-
1976-
RVAL="${RVAL//$'\x1'/\\u0001}"
1977-
RVAL="${RVAL//$'\x2'/\\u0002}"
1978-
RVAL="${RVAL//$'\x3'/\\u0003}"
1979-
RVAL="${RVAL//$'\x4'/\\u0004}"
1980-
RVAL="${RVAL//$'\x5'/\\u0005}"
1981-
RVAL="${RVAL//$'\x6'/\\u0006}"
1982-
RVAL="${RVAL//$'\x7'/\\u0007}"
1983-
RVAL="${RVAL//$'\xB'/\\u000B}"
1984-
RVAL="${RVAL//$'\xE'/\\u000E}"
1985-
RVAL="${RVAL//$'\xF'/\\u000F}"
1986-
RVAL="${RVAL//$'\x10'/\\u0010}"
1987-
RVAL="${RVAL//$'\x11'/\\u0011}"
1988-
RVAL="${RVAL//$'\x12'/\\u0012}"
1989-
RVAL="${RVAL//$'\x13'/\\u0013}"
1990-
RVAL="${RVAL//$'\x14'/\\u0014}"
1991-
RVAL="${RVAL//$'\x15'/\\u0015}"
1992-
RVAL="${RVAL//$'\x16'/\\u0016}"
1993-
RVAL="${RVAL//$'\x17'/\\u0017}"
1994-
RVAL="${RVAL//$'\x18'/\\u0018}"
1995-
RVAL="${RVAL//$'\x19'/\\u0019}"
1996-
RVAL="${RVAL//$'\x1A'/\\u001A}"
1997-
RVAL="${RVAL//$'\x1B'/\\u001B}"
1998-
RVAL="${RVAL//$'\x1C'/\\u001C}"
1999-
RVAL="${RVAL//$'\x1D'/\\u001D}"
2000-
RVAL="${RVAL//$'\x1E'/\\u001E}"
2001-
RVAL="${RVAL//$'\x1F'/\\u001F}"
2002-
}
1967+
RVAL="${*//\\/\\\\}"
1968+
1969+
RVAL="${RVAL//\"/\\\"}"
1970+
1971+
RVAL="${RVAL//$'\n'/\\n}"
1972+
1973+
RVAL="${RVAL//$'\r'/\\r}"
1974+
1975+
RVAL="${RVAL//$'\t'/\\t}"
1976+
1977+
RVAL="${RVAL//$'\b'/\\b}"
1978+
1979+
RVAL="${RVAL//$'\f'/\\f}"
1980+
1981+
RVAL="${RVAL//\//\\/}"
1982+
1983+
RVAL="${RVAL//$'\x1'/\\u0001}"
1984+
RVAL="${RVAL//$'\x2'/\\u0002}"
1985+
RVAL="${RVAL//$'\x3'/\\u0003}"
1986+
RVAL="${RVAL//$'\x4'/\\u0004}"
1987+
RVAL="${RVAL//$'\x5'/\\u0005}"
1988+
RVAL="${RVAL//$'\x6'/\\u0006}"
1989+
RVAL="${RVAL//$'\x7'/\\u0007}"
1990+
RVAL="${RVAL//$'\xB'/\\u000B}"
1991+
RVAL="${RVAL//$'\xE'/\\u000E}"
1992+
RVAL="${RVAL//$'\xF'/\\u000F}"
1993+
RVAL="${RVAL//$'\x10'/\\u0010}"
1994+
RVAL="${RVAL//$'\x11'/\\u0011}"
1995+
RVAL="${RVAL//$'\x12'/\\u0012}"
1996+
RVAL="${RVAL//$'\x13'/\\u0013}"
1997+
RVAL="${RVAL//$'\x14'/\\u0014}"
1998+
RVAL="${RVAL//$'\x15'/\\u0015}"
1999+
RVAL="${RVAL//$'\x16'/\\u0016}"
2000+
RVAL="${RVAL//$'\x17'/\\u0017}"
2001+
RVAL="${RVAL//$'\x18'/\\u0018}"
2002+
RVAL="${RVAL//$'\x19'/\\u0019}"
2003+
RVAL="${RVAL//$'\x1A'/\\u001A}"
2004+
RVAL="${RVAL//$'\x1B'/\\u001B}"
2005+
RVAL="${RVAL//$'\x1C'/\\u001C}"
2006+
RVAL="${RVAL//$'\x1D'/\\u001D}"
2007+
RVAL="${RVAL//$'\x1E'/\\u001E}"
2008+
RVAL="${RVAL//$'\x1F'/\\u001F}"
2009+
}
20032010

20042011

20052012

src/mulle-bashfunctions-all.sh

Lines changed: 55 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,7 +2079,10 @@ function r_escaped_sed_pattern()
20792079
s="${s//\*/\\*}"
20802080
s="${s//\./\\.}"
20812081
s="${s//\^/\\^}"
2082-
s="${s//$'\n'/\\$'\n'}" # assume
2082+
s="${s//$'\n'/\\$'\n'}"
2083+
s="${s//$'\t'/\\$'\t'}"
2084+
s="${s//$'\r'/\\$'\r'}"
2085+
s="${s//$'\f'/\\$'\f'}"
20832086

20842087
RVAL="$s"
20852088
}
@@ -2089,10 +2092,14 @@ function r_escaped_sed_replacement()
20892092
{
20902093
local s="$1"
20912094

2092-
s="${s//\\/\\\\}"
2093-
s="${s//\//\\/}"
2094-
s="${s//&/\\&}"
2095-
s="${s//$'\n'/\\$'\n'}"
2095+
s="${s//\\/\\\\}" # escape backslashes first
2096+
s="${s//\//\\/}" # escape forward slashes
2097+
s="${s//\'/\'\\\'\'}" # escape single quotes by closing and reopening the quote
2098+
s="${s//&/\\&}" # escape ampersands
2099+
s="${s//$'\t'/\\t}" # escape tabs returns
2100+
s="${s//$'\r'/\\r}" # escape crlf returns
2101+
s="${s//$'\n'/\\n}" # escape newlines returns
2102+
s="${s//$'\f'/\\f}" # escape form feeds returns
20962103

20972104
RVAL="$s"
20982105
}
@@ -2140,49 +2147,49 @@ function r_escaped_shell_string()
21402147

21412148
function r_escaped_json()
21422149
{
2143-
RVAL="${*//\\/\\\\}"
2144-
2145-
RVAL="${RVAL//\"/\\\"}"
2146-
2147-
RVAL="${RVAL//$'\n'/\\n}"
2148-
2149-
RVAL="${RVAL//$'\r'/\\r}"
2150-
2151-
RVAL="${RVAL//$'\t'/\\t}"
2152-
2153-
RVAL="${RVAL//$'\b'/\\b}"
2154-
2155-
RVAL="${RVAL//$'\f'/\\f}"
2156-
2157-
RVAL="${RVAL//\//\\/}"
2158-
2159-
RVAL="${RVAL//$'\x1'/\\u0001}"
2160-
RVAL="${RVAL//$'\x2'/\\u0002}"
2161-
RVAL="${RVAL//$'\x3'/\\u0003}"
2162-
RVAL="${RVAL//$'\x4'/\\u0004}"
2163-
RVAL="${RVAL//$'\x5'/\\u0005}"
2164-
RVAL="${RVAL//$'\x6'/\\u0006}"
2165-
RVAL="${RVAL//$'\x7'/\\u0007}"
2166-
RVAL="${RVAL//$'\xB'/\\u000B}"
2167-
RVAL="${RVAL//$'\xE'/\\u000E}"
2168-
RVAL="${RVAL//$'\xF'/\\u000F}"
2169-
RVAL="${RVAL//$'\x10'/\\u0010}"
2170-
RVAL="${RVAL//$'\x11'/\\u0011}"
2171-
RVAL="${RVAL//$'\x12'/\\u0012}"
2172-
RVAL="${RVAL//$'\x13'/\\u0013}"
2173-
RVAL="${RVAL//$'\x14'/\\u0014}"
2174-
RVAL="${RVAL//$'\x15'/\\u0015}"
2175-
RVAL="${RVAL//$'\x16'/\\u0016}"
2176-
RVAL="${RVAL//$'\x17'/\\u0017}"
2177-
RVAL="${RVAL//$'\x18'/\\u0018}"
2178-
RVAL="${RVAL//$'\x19'/\\u0019}"
2179-
RVAL="${RVAL//$'\x1A'/\\u001A}"
2180-
RVAL="${RVAL//$'\x1B'/\\u001B}"
2181-
RVAL="${RVAL//$'\x1C'/\\u001C}"
2182-
RVAL="${RVAL//$'\x1D'/\\u001D}"
2183-
RVAL="${RVAL//$'\x1E'/\\u001E}"
2184-
RVAL="${RVAL//$'\x1F'/\\u001F}"
2185-
}
2150+
RVAL="${*//\\/\\\\}"
2151+
2152+
RVAL="${RVAL//\"/\\\"}"
2153+
2154+
RVAL="${RVAL//$'\n'/\\n}"
2155+
2156+
RVAL="${RVAL//$'\r'/\\r}"
2157+
2158+
RVAL="${RVAL//$'\t'/\\t}"
2159+
2160+
RVAL="${RVAL//$'\b'/\\b}"
2161+
2162+
RVAL="${RVAL//$'\f'/\\f}"
2163+
2164+
RVAL="${RVAL//\//\\/}"
2165+
2166+
RVAL="${RVAL//$'\x1'/\\u0001}"
2167+
RVAL="${RVAL//$'\x2'/\\u0002}"
2168+
RVAL="${RVAL//$'\x3'/\\u0003}"
2169+
RVAL="${RVAL//$'\x4'/\\u0004}"
2170+
RVAL="${RVAL//$'\x5'/\\u0005}"
2171+
RVAL="${RVAL//$'\x6'/\\u0006}"
2172+
RVAL="${RVAL//$'\x7'/\\u0007}"
2173+
RVAL="${RVAL//$'\xB'/\\u000B}"
2174+
RVAL="${RVAL//$'\xE'/\\u000E}"
2175+
RVAL="${RVAL//$'\xF'/\\u000F}"
2176+
RVAL="${RVAL//$'\x10'/\\u0010}"
2177+
RVAL="${RVAL//$'\x11'/\\u0011}"
2178+
RVAL="${RVAL//$'\x12'/\\u0012}"
2179+
RVAL="${RVAL//$'\x13'/\\u0013}"
2180+
RVAL="${RVAL//$'\x14'/\\u0014}"
2181+
RVAL="${RVAL//$'\x15'/\\u0015}"
2182+
RVAL="${RVAL//$'\x16'/\\u0016}"
2183+
RVAL="${RVAL//$'\x17'/\\u0017}"
2184+
RVAL="${RVAL//$'\x18'/\\u0018}"
2185+
RVAL="${RVAL//$'\x19'/\\u0019}"
2186+
RVAL="${RVAL//$'\x1A'/\\u001A}"
2187+
RVAL="${RVAL//$'\x1B'/\\u001B}"
2188+
RVAL="${RVAL//$'\x1C'/\\u001C}"
2189+
RVAL="${RVAL//$'\x1D'/\\u001D}"
2190+
RVAL="${RVAL//$'\x1E'/\\u001E}"
2191+
RVAL="${RVAL//$'\x1F'/\\u001F}"
2192+
}
21862193

21872194

21882195

0 commit comments

Comments
 (0)