[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH] svn_cmdline__edit_file_externally() may not be able to open the target file in locale other than UTF-8

From: Stefan Sperling <stsp_at_elego.de>
Date: Sun, 20 Sep 2020 22:27:26 +0200

On Mon, Sep 21, 2020 at 01:18:54AM +0900, Yasuhito FUTATSUKI wrote:
> 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)
> ]]]
>

Yes, looks good to me. Thank you :)

> 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.)

I don't know Windows either.

Perhaps someone else reading this could test the patch?

> 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);
Received on 2020-09-20 22:27:37 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.