Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
database.py: check for non-string elements in array
Browse files Browse the repository at this point in the history
Added check for non-string elements in array.
Non-string elements are converted to strings by default.

Closes #79
  • Loading branch information
dhruvsomani authored and jayvdb committed Nov 17, 2018
1 parent 3255d2d commit 6cf802b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions statik/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,13 @@ def __init__(self, model=None, session=None, **kwargs):
field_name)
self.field_values[field_name] = list(set(self.field_values[field_name]))

# check if non-string items are present
for item in self.field_values[field_name]:
if not isinstance(item, ("".__class__, u"".__class__)):
logger.warning("Non-string values found in array " +
"(field: %s, instance: %s, model: %s): %s",
field_name, self.field_values['pk'], self.model.name, item)

# convert the list of field values to a query to look up the
# primary keys of the corresponding table
other_model = globals()[field.field_type]
Expand Down
8 changes: 8 additions & 0 deletions tests/modular/test_nonascii.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

TEST_MARKDOWN_CONTENT = """---
title: This is a “title” with some non-standard characters
unicode:
- "\u2ffa"
- "\u2ffb"
---
This is the “Markdown” body with some other non-standard characters.
"""
Expand All @@ -28,6 +32,10 @@ def test_parsing(self):
"This is a “title” with some non-standard characters",
parsed.vars['title'],
)
self.assertEqual(
['⿺', '⿻'],
parsed.vars['unicode']
)
self.assertEqual(
"<p>This is the “Markdown” body with some other non-standard characters.</p>",
parsed.content
Expand Down

0 comments on commit 6cf802b

Please sign in to comment.