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

Added code to handle null bytes in quill #28

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions delta/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,27 @@ def id_attribute(root, op):
})


def valid_xml_char_ordinal(c):
codepoint = ord(c)
# conditions ordered by presumed frequency
return (
codepoint in (0x9, 0xA, 0xD) or
0x20 <= codepoint <= 0xD7FF or
0xE000 <= codepoint <= 0xFFFD or
0x10000 <= codepoint <= 0x10FFFF
)


def append_text(_to, text):
try:
if _to:
_to += text
else:
_to = text
Comment on lines +638 to +640

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about _to += text but _to = text will not update last.tail. It will only update local variable _to. Same applies to root variable.

except ValueError:
text = ''.join(c for c in text if valid_xml_char_ordinal(c))
append_text(_to, text)

### Processors ###
def append_op(root, op):
for fmt in Format.all:
Expand All @@ -630,15 +651,9 @@ def append_op(root, op):
if isinstance(text, str) and text:
if list(root):
last = root[-1]
if last.tail:
last.tail += text
else:
last.tail = text
append_text(last.tail, text)
else:
if root.text:
root.text += text
else:
root.text = text
append_text(root.text, text)


def append_line(root, delta, attrs, index):
Expand Down