Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape " in JSON generation. #8579

Merged
merged 1 commit into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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