v.db.connect: accept layer number/name without parser warning#6997
v.db.connect: accept layer number/name without parser warning#6997Abhi-d-gr8 wants to merge 2 commits intoOSGeo:mainfrom
Conversation
wenzeslaus
left a comment
There was a problem hiding this comment.
I need to see more background discussion here to be confident enough to merge this. Tests for different use cases may help to facilitate that.
vector/v.db.connect/main.c
Outdated
| field_opt->description = _("Format: layer number[/layer name]"); | ||
| field_opt->gisprompt = "new,layer,layer"; | ||
| field_opt->description = | ||
| _("Layer number or name (format: layer number[/layer name])"); | ||
| /* no gisprompt override: allow layer_number/layer_name without filename | ||
| * validation */ |
There was a problem hiding this comment.
I don't know why new is here in the first place.
| self.assertNotIn("Illegal filename", m.outputs.stderr) | ||
| self.assertNotIn("Character </> not allowed", m.outputs.stderr) |
There was a problem hiding this comment.
Good, but not robust when case or wording changes (likely to happen if also the parameter handling changes).
| @@ -113,6 +114,13 @@ def test_columns_csv(self): | |||
| ).splitlines() | |||
| self.assertEqual(actual, expected) | |||
|
|
|||
| def test_layer_number_name_syntax_no_warning(self): | |||
| """layer=number/name should not trigger filename validation warnings""" | |||
| m = SimpleModule("v.db.connect", map="bridges", layer="1/bridges", flags="c") | |||
There was a problem hiding this comment.
The doc and general expectation is layer or number, so all these need test. Number only should be easy to test. I'm not clear about how name is actually supported here, while at same time, there is a lot of ways this tool can be used.
|
Hi @wenzeslaus, thanks for the review. I dug into this and the warning appears to come from the option parser, not v.db.connect logic. The module documents/prints layer number[/layer name] (e.g. 1/bridges), and the code already supports it by splitting on /. The Illegal filename … </> not allowed message is triggered because G_OPT_V_FIELD sets gisprompt such that the parser applies filename-style validation to the value. Clearing field_opt->gisprompt avoids that false-positive. Also agreed on your note about "new" that doesn’t seem relevant over here to me as well. Lastly I have added tests for layer=1, layer=bridges, and layer=1/bridges in both -c and -p, and the regression check is robust like you wanted. |
Fixes #6100
v.db.connect advertises and prints the layer number[/layer name] syntax, but using layer=1/name triggered a parser warning:
Illegal filename <1/name>. Character </> not allowed. This was caused by filename validation being enabled for the layer option via field_opt->gisprompt. This PR removes that override so the documented number/name syntax works without warnings, and adds a regression test to ensure no warning is emitted.
@wenzeslaus