Allow dots in identifiers and strip surrounding quotes in validate_identifier
Supports iSeries schema names that contain dots (e.g. CMS.CUSLG). Strips surrounding double quotes on input so users don't need to worry about quoting — the driver's quote_identifier handles that when building SQL. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
f39b1df75e
commit
bb4f7712d2
@ -66,11 +66,16 @@ class RemoteColumn:
|
||||
# identifiers; reject everything else before it reaches a query.
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
_SAFE_IDENT = re.compile(r"^[A-Za-z_][A-Za-z0-9_$#]*$")
|
||||
_SAFE_IDENT = re.compile(r"^[A-Za-z_][A-Za-z0-9_$#.]*$")
|
||||
|
||||
|
||||
def validate_identifier(value: str, field_name: str = "identifier") -> str:
|
||||
if not isinstance(value, str) or not _SAFE_IDENT.match(value):
|
||||
if not isinstance(value, str):
|
||||
raise ValueError(f"invalid {field_name}: {value!r}")
|
||||
# Strip surrounding double quotes — caller should pass the bare name
|
||||
if value.startswith('"') and value.endswith('"') and len(value) > 2:
|
||||
value = value[1:-1]
|
||||
if not _SAFE_IDENT.match(value):
|
||||
raise ValueError(f"invalid {field_name}: {value!r}")
|
||||
return value
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user