mirror of
				https://github.com/nvm-sh/nvm.git
				synced 2025-11-04 13:21:29 +08:00 
			
		
		
		
	Path lists in environmental variables often give special meaning to empty entries (e.g. in PATH or MANPATH). These are represented by leading or trailing colons, or by doubled colons in the middle of the list. Adjust the awk invocation to correctly deal with trailing colons by printing the separator before every field except the first, and then printing the final separator that is read from the input - this will either be a colon or the null string. This preserves leading and trailing colons in all cases while not adding extra colons in the wrong place. Add test to confirm the correct behaviour. Fixes #3144
		
			
				
	
	
		
			25 lines
		
	
	
		
			943 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			25 lines
		
	
	
		
			943 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
#!/bin/sh
 | 
						|
 | 
						|
die () { echo "$@" ; exit 1; }
 | 
						|
 | 
						|
\. ../../../nvm.sh
 | 
						|
 | 
						|
TEST_PATH=$NVM_DIR/v0.10.5/bin:/usr/bin:$NVM_DIR/v0.11.5/bin:$NVM_DIR/v0.9.5/bin:/usr/local/bin:$NVM_DIR/v0.2.5/bin:$NVM_DIR/versions/node/v0.12.0/bin:$NVM_DIR/versions/io.js/v1.0.0/bin
 | 
						|
 | 
						|
STRIPPED_PATH=`nvm_strip_path "$TEST_PATH" "/bin"`
 | 
						|
 | 
						|
[ "$STRIPPED_PATH" = "/usr/bin:/usr/local/bin" ] || die "Not correctly stripped: $STRIPPED_PATH "
 | 
						|
 | 
						|
NVM_DIR='/#*.^$[]'
 | 
						|
TEST_PATH="$NVM_DIR/v0.10.5/bin:/usr/bin:$NVM_DIR/v0.11.5/bin:$NVM_DIR/v0.9.5/bin:/usr/local/bin:$NVM_DIR/v0.2.5/bin:$NVM_DIR/versions/node/v0.12.0/bin:$NVM_DIR/versions/io.js/v1.0.0/bin"
 | 
						|
 | 
						|
STRIPPED_PATH=`nvm_strip_path "$TEST_PATH" "/bin"`
 | 
						|
 | 
						|
[ "$STRIPPED_PATH" = "/usr/bin:/usr/local/bin" ] || die "Not correctly stripped: $STRIPPED_PATH "
 | 
						|
 | 
						|
TEST_PATH=":/a/b/bin::/c/d/bin:"
 | 
						|
 | 
						|
STRIPPED_PATH=`nvm_strip_path "$TEST_PATH" "/bin"`
 | 
						|
 | 
						|
[ "$STRIPPED_PATH" = "$TEST_PATH" ] || die "Stripping does not preserve colons: $STRIPPED_PATH "
 |