[Bug] legalize_vector_name does not escape SQL keywords case-insensitively

Aperta Adatta ai principianti
#8,150 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
83/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
c, python
Ambito
backend, databases

Direzione di ricerca

Leggi python/grass/script/utils.py in corrispondenza di legalize_vector_name() e confronta il controllo delle parole chiave con lib/vector/Vlib/legal_vname.c. Aggiungi o aggiorna test mirati per le parole chiave SQL in minuscolo e con maiuscole e minuscole miste, quindi esegui i test Python pertinenti. Il lavoro è completato quando tutte le varianti di maiuscole e minuscole vengono legalizzate in modo coerente con la funzione C.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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 loading python/grass/script/utils.py directly with Python 3.12

Additional context

Related but different: #3615 (SQL keywords as attribute column names).

Lingua principale
C
Stelle
1.2k
Fork
447
Merge medio
2g 59m
PR unite (30g)
63

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di OSGeo/grass

Tutte le issue di OSGeo/grass

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.