Skip to content

Commit

Permalink
Merge pull request #8579 from rtibbles/ancestors_fix
Browse files Browse the repository at this point in the history
Escape " in JSON generation.
  • Loading branch information
rtibbles committed Nov 3, 2021
2 parents 72e06e2 + 8e5c468 commit 7614857
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions kolibri/core/content/test/test_annotation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import tempfile
import uuid

from django.core.exceptions import ValidationError
from django.core.management import call_command
from django.db import DataError
from django.test import TestCase
Expand Down Expand Up @@ -919,3 +920,17 @@ def test_ancestors(self):
set_channel_ancestors(channel_id)
for n in ContentNode.objects.filter(channel_id=channel_id):
self.assertEqual(n.ancestors, list(n.get_ancestors().values("id", "title")))

def test_ancestors_quotation_marks_in_title(self):
builder = ChannelBuilder()
builder._django_nodes[0].title = 'Title with "A title!" in it!'
builder.insert_into_default_db()
channel_id = builder.channel["id"]
set_channel_ancestors(channel_id)
try:
for n in ContentNode.objects.filter(channel_id=channel_id):
self.assertEqual(
n.ancestors, list(n.get_ancestors().values("id", "title"))
)
except ValidationError:
self.fail("Did not coerce to proper JSON")
2 changes: 1 addition & 1 deletion kolibri/core/content/utils/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ def set_channel_ancestors(channel_id):
)
+ parent_id_expression
+ '","title": "'
+ parent.c.title
+ func.replace(parent.c.title, '"', '\\"')
+ '"}]'
]
).where(
Expand Down

0 comments on commit 7614857

Please sign in to comment.