git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/3] Fix sed string regex escaping in module_name.

From
RWRalf Wildenhues <ralf.wildenhues@gmx.de>
Date
Nov 8, 2007, 21:48 UTC
Message-ID
<20071108214849.GI31439@ins.uni-bonn.de>
In-Reply-To
<20071108214624.GF31439@ins.uni-bonn.de>

When escaping a string to be used as a sed regex, it is important to only escape active characters. Escaping other characters is undefined according to POSIX, and in practice leads to issues with extensions such as GNU sed's \+.

Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
---
 git-submodule.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 1c656be..82ac28f 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -74,7 +74,7 @@ resolve_relative_url ()
 module_name()
 {
 	# Do we have "submodule.<something>.path = $1" defined in .gitmodules file?
-	re=$(printf '%s' "$1" | sed -e 's/\([^a-zA-Z0-9_]\)/\\\1/g')
+	re=$(printf '%s' "$1" | sed -e 's/[].[^$\\*]/\\&/g')
 	name=$( GIT_CONFIG=.gitmodules \
 		git config --get-regexp '^submodule\..*\.path$' |
 		sed -n -e 's|^submodule\.\(.*\)\.path '"$re"'$|\1|p' )
-- 
1.5.3.5.561.g140d
Previous: Benoit Sigoure
Message 5 of 5 in “some shell portability fixes, v2”
  1. 0/3 some shell portability fixes, v2Ralf Wildenhues, Nov 8, 2007
  2. 1/3 Avoid a few unportable, needlessly nested "...`...".Ralf Wildenhues, Nov 8, 2007
  3. 2/3 Fix sed script to work with AIX and BSD sed.Ralf Wildenhues, Nov 8, 2007
  4. Benoit SigoureNov 8, 2007
  5. 3/3 Fix sed string regex escaping in module_name.Ralf Wildenhues, Nov 8, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.