Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-15379

Handling accents in program arguments

    XMLWordPrintable

Details

    • qtbase/c1e24f883824ad894aa121568e4fde8553028d95; qt/a9a468e0967448f6dcfd85264afa18d68e9e0c23

    Description

      In Windows it is appropriate to associate a program to a file extension. For a file named myfile.myext, with myapp.exe associated to the extension myext, typically myapp.exe is called with the following command line:
      "path_to_my_app\myapp.exe" "path_to_myfile\myfile.myext"
      All the user has to do, is double-clicking on myfile.myext to start myapp for myfile.ext. Windows creates above commandline and starts the application.
      If myfile.myext its name start with an accent, such as eg.: 'accentedName.myext (including the accent) the command line will be "path_to_my_app\myapp.exe" "path_to_myfile\'accentedName.myext"

      template<typename Char>
      static QVector<Char*> qWinCmdLine(Char *cmdParam, int length, int &argc)
      in 
      path_to_qt\src\corelib\kernel\qcorecmdlineargs_p.h 
      will interpret it as
      argv [0] = "path_to_my_app\myapp.exe"
      argv [1] = "path_to_myfile'accentedName.myext"
      Note: argv [1] looses the back-slash symbol, for \' is interpreted as an escape sequence.
      
      concerned code:
                      if (*p == '\\') {                // escape char?
                          p++;
                          if (*p == Char('\"') || *p == Char('\''))
                              ;                        // yes
                          else
                              p--;                        // treat \ literally
      
      My suggestion: not to escape if ' or " is not the qoute-character:
                      if (*p == '\\') {                // escape char?
                          p++;
                          if (*p != qoute)
                              p--;                        // treat \ literally, unless followed by quote character
      

      Another solution would be to interpret a program parameter specifying whether to interpret the escape sequence or not. For instance -noEscapeQuote
      "path_to_my_app\myapp.exe" -noEscapeQuote "path_to_myfile\'accentedName.myext"
      could leave the (next) program argument unchanged.
      "path_to_my_app\myapp.exe" "path_to_myfile\'accentedName.myext"
      would interpreted in the actual way.

      An actual workaround in Windows could be by explicitly calling GetCommandLine and using a function inspired by qWinCmdLine and the remarks above.

      Similar remarks are valid if a folder in the path to the application first letter is an accent.

      Attachments

        1. bugAccent.zip
          1.44 MB
          Geert Mys

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              jolind Jorgen Lind
              qtmryo Geert Mys (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes