mirror of
				git://git.code.sf.net/p/cdesktopenv/code
				synced 2025-03-09 15:50:02 +00:00 
			
		
		
		
	test foo =~ foo should fail with exit status 2 (#245)
				
					
				
			When test is passed the '=~' operator, it will silently fail with
exit status 1:
    $ test foo =~ foo; echo $?
    1
This bug is caused by test_binop reaching the 'NOTREACHED' area of
code. The bugfix was adapted from ksh2020:
https://github.com/att/ast/issues/1152
src/cmd/ksh93/bltins/test.c: test_binop():
- Error out with a message suggesting usage of '[[ ... ]]' if '=~'
  is passed to the test builtin.
- Special-case TEST_END (']]') as that is not really an operator.
Co-authored-by: Martijn Dekker <martijn@inlv.org>
			
			
This commit is contained in:
		
							parent
							
								
									767d23b3fe
								
							
						
					
					
						commit
						fc2d5a6019
					
				
					 6 changed files with 51 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -510,7 +510,6 @@ int test_binop(Shell_t *shp,register int op,const char *left,const char *right)
 | 
			
		|||
	}
 | 
			
		||||
	switch(op)
 | 
			
		||||
	{
 | 
			
		||||
		/* op must be one of the following values */
 | 
			
		||||
		case TEST_AND:
 | 
			
		||||
		case TEST_OR:
 | 
			
		||||
			return(*left!=0);
 | 
			
		||||
| 
						 | 
				
			
			@ -544,9 +543,20 @@ int test_binop(Shell_t *shp,register int op,const char *left,const char *right)
 | 
			
		|||
			return(lnum>=rnum);
 | 
			
		||||
		case TEST_LE:
 | 
			
		||||
			return(lnum<=rnum);
 | 
			
		||||
		default:
 | 
			
		||||
		{
 | 
			
		||||
			/* fallback for operators not supported by the test builtin */
 | 
			
		||||
			int i=0;
 | 
			
		||||
			char *e_msg;
 | 
			
		||||
			while(shtab_testops[i].sh_number && shtab_testops[i].sh_number != op)
 | 
			
		||||
				i++;
 | 
			
		||||
			if(op==TEST_END)
 | 
			
		||||
				e_msg = e_badop;
 | 
			
		||||
			else
 | 
			
		||||
				e_msg = e_unsupported_op;
 | 
			
		||||
			errormsg(SH_DICT,ERROR_exit(2),e_msg,shtab_testops[i].sh_name);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	/* NOTREACHED */
 | 
			
		||||
	return(0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue