[Bug] legalize_vector_name does not escape SQL keywords case-insensitively
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 83/100
Research direction
Read python/grass/script/utils.py at legalize_vector_name() and compare its keyword check with lib/vector/Vlib/legal_vname.c. Add or update focused tests for lowercase and mixed-case SQL keywords, then run the relevant Python tests. Done means all casing variants are legalized consistently with the C function.
Written by the indexing model from the issue text.
Description
Describe the bug
grass.script.utils.legalize_vector_name() only escapes the SQL keywords and, or and not when they are lowercase. Any other casing is returned unchanged, so the function returns names that GRASS itself rejects as illegal.
The Python function says it is based on Vect_legal_filename(), but the C function compares the keywords case-insensitively (lib/vector/Vlib/legal_vname.c):
static const char *keywords[] = {"and", "or", "not", NULL};
...
if (G_strcasecmp(buf, keywords[i]) == 0) {
while the Python version uses an exact match (python/grass/script/utils.py):
keywords = ["and", "or", "not"]
if name in keywords:
name = "{name}_".format(**locals())
To reproduce
from grass.script.utils import legalize_vector_name
for name in ["and", "AND", "Or", "nOt"]:
print(repr(name), "->", repr(legalize_vector_name(name)))
Output on current main:
'and' -> 'and_'
'AND' -> 'AND'
'Or' -> 'Or'
'nOt' -> 'nOt'
AND, Or and nOt are then rejected by Vect_legal_filename() with "SQL keyword cannot be used as vector map name".
Expected behavior
All casings of the keywords are made legal, e.g. 'AND' -> 'AND_', matching the case-insensitive check in Vect_legal_filename(). A fix would be to compare name.lower() against the keyword list.
System description
- Operating System: Windows 11
- GRASS version:
main(b0a6d7703c); the function is pure Python, reproduced by loadingpython/grass/script/utils.pydirectly with Python 3.12
Additional context
Related but different: #3615 (SQL keywords as attribute column names).
- Dominant language
- C
- Stars
- 1.2k
- Forks
- 447
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 62
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from OSGeo/grass
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
[Bug] v.db.addtable expands $MAP only when it is a directoryPossibly taken @alteralto claimed this 17 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
[Bug] grass.pygrass: Cats.delete(0) deletes all layer categories instead of category 0Possibly taken @Mohit-Ak claimed this 22 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
[Bug] macOS: Startup crashes with StopIteration when ~/Documents is not readable (macOS privacy protection)Possibly taken @NIne-WIngEd claimed this 28 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
OSGeo/grass#8027 · 3 comments ·
Maintainers usually reply within 1 day
-
[Bug] Specify the test project namePossibly taken @Om23131212 claimed this 21 days ago. Openbug
Difficulty 1/5 Under an hour Newbie friendliness 65/100
OSGeo/grass#7860 · 1 comment ·
Maintainers usually reply within 1 day
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
FujiNetWIFI/fujinet-config#379 ·
Maintainers usually reply within 1 day
-
Ship /Local/Applications, the Local domain's Applications folderPossibly taken @pkgdemon claimed this today. Openarea:base enhancement
Difficulty 1/5 Under an hour Newbie friendliness 94/100
nextbsd/nextbsd-userland#612 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
zephyrproject-rtos/zephyr#125543 ·
Maintainers usually reply within 2 days
-
good first issue needs-triage
Difficulty 1/5 Under an hour Newbie friendliness 88/100
InauguralSystems/EigenScript#2347 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
colbymchenry/codegraph#3277 ·
Maintainers usually reply within 1 day