On 2020/09/20 23:53, Yasuhito FUTATSUKI wrote:
> On 2020/09/20 23:41, Stefan Sperling wrote:
>> On Sun, Sep 20, 2020 at 11:06:21PM +0900, Yasuhito FUTATSUKI wrote:
>>> On 2020/09/19 5:26, Yasuhito FUTATSUKI wrote:

>> It looks like apr_escape_shell() will escape 0x5c (backslash, \) when
>> looking for ASCII character bytes. When 0x5c is escaped this breaks the
>> SJIS-encoded byte sequence.
> 
> Yes, it is right.
> 
>> Have you already tried always using escape_path() on the UTF-8 version of
>> the string, and then converting the escaped path to the locale's encoding?
>> In other words: First use escape_path, then use svn_path_cstring_from_utf8?
>> Perhaps that will make SJIS work?
> 
> Ah, I didn't make sense. I'll try and then post a new patch.
> Thank you very much!

I've tried and it works on SJIS environment. Thanks.

I attached an updated patch. (fix-edit-file-externally-patch-v2.txt)
[[[
Fix file name to edit from utf8 to local style.

* subversion/libsvn_subr/cmdline.c (svn_cmdline__edit_file_externally):
  Apply svn_path_cstring_from_utf8() to target file name after escape_shell().

Suggested by: stsp (applying order of file name conversion)  
]]]

Parhaps even with this patch, it may not work on Windows system other than
UTF-8 code page, because svn_path_cstring_from_utf8() returns just same
string as input and system() will interpret with system active code page.
(I don't know Windows so much, so I leave it.)

Cheers,
-- 
Yasuhito FUTATSUKI <futat...@yf.bsclub.org>
Index: subversion/libsvn_subr/cmdline.c
===================================================================
--- subversion/libsvn_subr/cmdline.c    (revision 1881848)
+++ subversion/libsvn_subr/cmdline.c    (working copy)
@@ -1400,6 +1400,7 @@
                                   apr_pool_t *pool)
 {
   const char *editor, *cmd, *base_dir, *file_name, *base_dir_apr;
+  const char *file_name_local;
   char *old_cwd;
   int sys_err;
   apr_status_t apr_err;
@@ -1423,9 +1424,11 @@
     return svn_error_wrap_apr
       (apr_err, _("Can't change working directory to '%s'"), base_dir);
 
+  SVN_ERR(svn_path_cstring_from_utf8(&file_name_local, 
+                                     escape_path(pool, file_name), pool));
   /* editor is explicitly documented as being interpreted by the user's shell,
      and as such should already be quoted/escaped as needed. */
-  cmd = apr_psprintf(pool, "%s %s", editor, escape_path(pool, file_name));
+  cmd = apr_psprintf(pool, "%s %s", editor, file_name_local);
   sys_err = system(cmd);
 
   apr_err = apr_filepath_set(old_cwd, pool);

Reply via email to