Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: --code flag cannot accept paths with single quote (') #60120

Open
2 tasks done
btzy opened this issue Jan 12, 2025 · 1 comment · May be fixed by #60121 or #60134
Open
2 tasks done

Windows: --code flag cannot accept paths with single quote (') #60120

btzy opened this issue Jan 12, 2025 · 1 comment · May be fixed by #60121 or #60134
Assignees
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter!

Comments

@btzy
Copy link

btzy commented Jan 12, 2025

What is the bug or the crash?

The --code flag, passed to qgis.exe, is meant to make QGIS execute a Python script after starting up. However, if the argument of --code has the ' character, QGIS isn't able to open the script. It seems that QGIS doesn't properly escape the filename.

Steps to reproduce the issue

  1. Create a Python script containing a ' character, for example hawai'i.py.
  2. Open Command Prompt.
  3. Run QGIS with the script passed in the --code argument, .e.g "C:\\Program Files\\QGIS 3.40.2\\bin\\qgis-bin.exe" --code "hawai'i.py".
  4. QGIS opens an error window containing the following error:
An error occurred during execution of following code:
with open('E:/tmp/hawai'i.py','r') as f: exec(f.read())


  File "", line 1
    with open('E:/tmp/hawai'i.py','r') as f: exec(f.read())
                                   ^
SyntaxError: unterminated string literal (detected at line 1)


Python version:
3.12.8 (main, Dec 20 2024, 15:21:15) [MSC v.1938 64 bit (AMD64)]

QGIS version:
3.40.2-Bratislava 'Bratislava', 14826ca1

Versions

QGIS version3.40.2-Bratislava
QGIS code revision14826ca1
 
Libraries
Qt version5.15.13
Python version3.12.8
GDAL/OGR version3.9.3
PROJ version9.5.0
EPSG Registry database versionv11.016 (2024-08-31)
GEOS version3.13.0-CAPI-1.19.0
SQLite version3.46.1
PDAL version2.8.1
PostgreSQL client version16.2
SpatiaLite version5.1.0
QWT version6.3.0
QScintilla2 version2.14.1
OS versionWindows 10 Version 2009
 
Active Python plugins
MetaSearch0.3.6
processing2.12.99

Supported QGIS version

  • I'm running a supported QGIS version according to the roadmap.

New profile

Additional context

QGIS ought to correctly escape the filename before plonking it into Python code.

@btzy btzy added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Jan 12, 2025
@agiudiceandrea agiudiceandrea self-assigned this Jan 12, 2025
@agiudiceandrea
Copy link
Contributor

Thanks for reporting. See #60121.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter!
Projects
None yet
2 participants