mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	dir.c: FNM_SHORTNAME
* dir.c (dirent_match): match short names only when FNM_SHORTNAME flag is given, for the backward compatibility, and the new behavior is often dangerous. [ruby-core:69435] [Bug #11206] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50760 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									99487313fd
								
							
						
					
					
						commit
						9375ff5b06
					
				
					 3 changed files with 23 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -1,3 +1,9 @@
 | 
			
		|||
Thu Jun  4 07:12:20 2015  Nobuyoshi Nakada  <nobu@ruby-lang.org>
 | 
			
		||||
 | 
			
		||||
	* dir.c (dirent_match): match short names only when FNM_SHORTNAME
 | 
			
		||||
	  flag is given, for the backward compatibility, and the new
 | 
			
		||||
	  behavior is often dangerous.  [ruby-core:69435] [Bug #11206]
 | 
			
		||||
 | 
			
		||||
Thu Jun  4 05:44:01 2015  Eric Wong  <e@80x24.org>
 | 
			
		||||
 | 
			
		||||
	* variable.c (special_generic_ivar): remove flag
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										14
									
								
								dir.c
									
										
									
									
									
								
							
							
						
						
									
										14
									
								
								dir.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -157,6 +157,11 @@ has_nonascii(const char *ptr, size_t len)
 | 
			
		|||
#else
 | 
			
		||||
#define FNM_SYSCASE	0
 | 
			
		||||
#endif
 | 
			
		||||
#if _WIN32
 | 
			
		||||
#define FNM_SHORTNAME	0x20
 | 
			
		||||
#else
 | 
			
		||||
#define FNM_SHORTNAME	0
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define FNM_NOMATCH	1
 | 
			
		||||
#define FNM_ERROR	2
 | 
			
		||||
| 
						 | 
				
			
			@ -1595,7 +1600,7 @@ dirent_match(const char *pat, rb_encoding *enc, const char *name, const struct d
 | 
			
		|||
{
 | 
			
		||||
    if (fnmatch(pat, enc, name, flags) == 0) return 1;
 | 
			
		||||
#ifdef _WIN32
 | 
			
		||||
    if (dp->d_altname) {
 | 
			
		||||
    if (dp->d_altname && (flags & FNM_SHORTNAME)) {
 | 
			
		||||
	if (fnmatch(pat, enc, dp->d_altname, flags) == 0) return 1;
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			@ -2636,4 +2641,11 @@ Init_Dir(void)
 | 
			
		|||
     *  0.
 | 
			
		||||
     */
 | 
			
		||||
    rb_file_const("FNM_SYSCASE", INT2FIX(FNM_SYSCASE));
 | 
			
		||||
 | 
			
		||||
    /*  Document-const: File::Constants::FNM_SHORTNAME
 | 
			
		||||
     *
 | 
			
		||||
     *  Makes patterns to match short names if existing.  Valid only
 | 
			
		||||
     *  on Microsoft Windows.
 | 
			
		||||
     */
 | 
			
		||||
    rb_file_const("FNM_SHORTNAME", INT2FIX(FNM_SHORTNAME));
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -262,6 +262,7 @@ class TestDir < Test::Unit::TestCase
 | 
			
		|||
  if /mswin|mingw/ =~ RUBY_PLATFORM
 | 
			
		||||
    def test_glob_legacy_short_name
 | 
			
		||||
      bug10819 = '[ruby-core:67954] [Bug #10819]'
 | 
			
		||||
      bug11206 = '[ruby-core:69435] [Bug #11206]'
 | 
			
		||||
      skip unless /\A\w:/ =~ ENV["ProgramFiles"]
 | 
			
		||||
      short = "#$&/PROGRA~1"
 | 
			
		||||
      skip unless File.directory?(short)
 | 
			
		||||
| 
						 | 
				
			
			@ -270,8 +271,9 @@ class TestDir < Test::Unit::TestCase
 | 
			
		|||
      long = File.expand_path(short)
 | 
			
		||||
      assert_equal(Dir.glob("#{long}/Common*"), entries, bug10819)
 | 
			
		||||
      wild = short.sub(/1\z/, '*')
 | 
			
		||||
      assert_include(Dir.glob(wild), long, bug10819)
 | 
			
		||||
      assert_empty(entries - Dir.glob("#{wild}/Common*"), bug10819)
 | 
			
		||||
      assert_not_include(Dir.glob(wild), long, bug11206)
 | 
			
		||||
      assert_include(Dir.glob(wild, File::FNM_SHORTNAME), long, bug10819)
 | 
			
		||||
      assert_empty(entries - Dir.glob("#{wild}/Common*", File::FNM_SHORTNAME), bug10819)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue