@@ -3293,6 +3293,60 @@ def keep_local_reverted_properly(sbox):
3293
3293
svntest .actions .run_and_verify_status (wc_dir , expected_output )
3294
3294
3295
3295
3296
+ @SkipUnless (svntest .main .is_os_windows )
3297
+ def argv_with_best_fit_chars (sbox ):
3298
+ """argv with best fit chars"""
3299
+
3300
+ import ctypes
3301
+ from ctypes import windll , wintypes
3302
+
3303
+ CP_ACP = 0
3304
+ kernel32 = windll .kernel32
3305
+ WideCharToMultiByte = kernel32 .WideCharToMultiByte
3306
+ WideCharToMultiByte .argtypes = [
3307
+ wintypes .UINT , wintypes .DWORD , wintypes .LPCWSTR , ctypes .c_int ,
3308
+ wintypes .LPSTR , ctypes .c_int , wintypes .LPCSTR , wintypes .LPBOOL ,
3309
+ ]
3310
+ WideCharToMultiByte .restype = ctypes .c_int
3311
+ codepage = kernel32 .GetACP ()
3312
+
3313
+ def regexlines (* patterns ):
3314
+ return svntest .verify .RegexListOutput (list (patterns ), match_all = True )
3315
+
3316
+ def iter_bestfit_chars ():
3317
+ chars = {b'"' : 0 , b'\\ ' : 0 , b' ' : 0 }
3318
+ for c in range (0x80 , 0x10000 ):
3319
+ wcs = ctypes .create_unicode_buffer (chr (c ))
3320
+ mbcs = ctypes .create_string_buffer (8 )
3321
+ rc = WideCharToMultiByte (CP_ACP , 0 , wcs , len (wcs ), mbcs , len (mbcs ), None ,
3322
+ None )
3323
+ if rc == 0 :
3324
+ continue
3325
+ mbcs = mbcs .value
3326
+ if chars .get (mbcs ) != 0 :
3327
+ continue
3328
+ chars [mbcs ] = c
3329
+ yield chr (c ), mbcs
3330
+
3331
+ count = 0
3332
+ expected_stderr = svntest .verify .RegexListOutput (
3333
+ [r'^"foo.+bar": unknown command\.\n$' , '\n ' ], match_all = True )
3334
+ for wc , mbcs in iter_bestfit_chars ():
3335
+ count += 1
3336
+ logger .info ('Code page %r - U+%04x -> 0x%s' , codepage , ord (wc ), mbcs .hex ())
3337
+ if mbcs == b'"' :
3338
+ svntest .actions .run_and_verify_svn2 (None , expected_stderr , 0 , 'help' ,
3339
+ 'foo{0} {0}bar' .format (wc ))
3340
+ elif mbcs == b'\\ ' :
3341
+ svntest .actions .run_and_verify_svn2 (None , expected_stderr , 0 , 'help' ,
3342
+ 'foo{0}" {0}"bar' .format (wc ))
3343
+ elif mbcs == b' ' :
3344
+ svntest .actions .run_and_verify_svn2 (None , expected_stderr , 0 , 'help' ,
3345
+ 'foo{0}bar' .format (wc ))
3346
+ if count == 0 :
3347
+ raise svntest .Skip ('No best fit characters in code page %r' % codepage )
3348
+
3349
+
3296
3350
########################################################################
3297
3351
# Run the tests
3298
3352
@@ -3369,6 +3423,7 @@ def keep_local_reverted_properly(sbox):
3369
3423
null_prop_update_last_changed_revision ,
3370
3424
filtered_ls_top_level_path ,
3371
3425
keep_local_reverted_properly ,
3426
+ argv_with_best_fit_chars ,
3372
3427
]
3373
3428
3374
3429
if __name__ == '__main__' :
0 commit comments