Skip to content

Commit 26acd3d

Browse files
committed
to nul_byte
1 parent 14288bf commit 26acd3d

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

ckan/logic/schema/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,14 +498,14 @@ def user_new_form_schema(
498498
@validator_args
499499
def request_reset_form_schema(
500500
not_empty: Validator, unicode_safe: Validator,
501-
no_nul_characters: Validator) -> Schema:
501+
no_nul_byte: Validator) -> Schema:
502502
'''Schema for the /user/reset form (request a password-reset link).
503503
504504
Guards the ``user`` field against NUL bytes that would otherwise crash
505505
psycopg2 when the value is used to look the user up in Postgres.
506506
'''
507507
return {
508-
'user': [not_empty, no_nul_characters, unicode_safe],
508+
'user': [not_empty, no_nul_byte, unicode_safe],
509509
}
510510

511511

ckan/logic/validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def group_id_or_name_exists(reference: str, context: Context) -> Any:
367367
return reference
368368

369369

370-
def no_nul_characters(value: Any, context: Context) -> Any:
370+
def no_nul_byte(value: Any, context: Context) -> Any:
371371
'''Reject strings containing the NUL character (U+0000).
372372
373373
PostgreSQL ``text`` columns cannot store the NUL byte and ``psycopg2``

ckan/tests/logic/test_validators.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ def call_validator(*args, **kwargs):
356356
call_validator(valid_value)
357357

358358

359-
def test_no_nul_characters_with_invalid_value():
360-
"""no_nul_characters() should raise Invalid for any string containing
359+
def test_no_nul_byte_with_invalid_value():
360+
"""no_nul_byte() should raise Invalid for any string containing
361361
the NUL byte. PostgreSQL text columns reject NUL and psycopg2 raises
362362
ValueError before the query is sent, so unguarded input becomes a 500.
363363
"""
@@ -371,11 +371,11 @@ def test_no_nul_characters_with_invalid_value():
371371
]
372372

373373
for invalid_value in invalid_values:
374-
raises_invalid(validators.no_nul_characters)(invalid_value, context={})
374+
raises_invalid(validators.no_nul_byte)(invalid_value, context={})
375375

376376

377-
def test_no_nul_characters_with_valid_value():
378-
"""no_nul_characters() should return the value unchanged for any string
377+
def test_no_nul_byte_with_valid_value():
378+
"""no_nul_byte() should return the value unchanged for any string
379379
that doesn't contain the NUL byte, including strings with other control
380380
characters and non-ASCII Unicode (which PostgreSQL accepts)."""
381381
valid_values = [
@@ -391,7 +391,7 @@ def test_no_nul_characters_with_valid_value():
391391
]
392392

393393
for valid_value in valid_values:
394-
returns_arg(validators.no_nul_characters)(valid_value)
394+
returns_arg(validators.no_nul_byte)(valid_value)
395395

396396

397397
def test_strip_value_with_valid_value():

0 commit comments

Comments
 (0)