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

Add validation for Pango Markup - Fixes #8 #9

Merged
merged 9 commits into from Jan 11, 2021

Conversation

PhilippImhof
Copy link
Member

Fixes #8

@PhilippImhof
Copy link
Member Author

As soon as this is merged, I file another PR for the change of MarkupText in Manim

def validate(text: str) -> bool:
cdef GError** res = NULL
text_bytes = text.encode("utf-8")
return pango_parse_markup(text_bytes, len(text_bytes), 0, NULL, NULL, NULL, res)
Copy link
Member

Choose a reason for hiding this comment

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

I think res is NULLABLE, so if we aren't using it then it can be NULL. Also, len(text_bytes) isn't required. Instead it can be -1 and Pango calculates the length.

Suggested change
return pango_parse_markup(text_bytes, len(text_bytes), 0, NULL, NULL, NULL, res)
return pango_parse_markup(text_bytes, -1, 0, NULL, NULL, NULL, NULL)

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right, it actually works even if res is NULL. The docs said the function would return false if error was set, so I'd better give a real pointer. For the length, I suggest keeping this. It does not cost us anything and automatic determination of length will fail if \0 is in the string (no idea why anyone would want that in their string, but still). My experience tells me it is always better to indicate the length, if this can be done "for free".

Copy link
Member

Choose a reason for hiding this comment

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

Looks like this is causing some compiler warnings on Windows.
See https://github.com/ManimCommunity/ManimPango/runs/1696088350?check_suite_focus=true#step:5:96
doing like this fixes it

return pango_parse_markup(text_bytes, <int>len(text_bytes), 0, NULL, NULL, NULL, res)

I have done this in #12

manimpango/cmanimpango.pxd Outdated Show resolved Hide resolved
manimpango/cmanimpango.pxd Outdated Show resolved Hide resolved
manimpango/cmanimpango.pxd Outdated Show resolved Hide resolved
manimpango/cmanimpango.pxd Outdated Show resolved Hide resolved
@naveen521kk
Copy link
Member

Also, it would be good to have a small test for that :)

@PhilippImhof
Copy link
Member Author

Also, it would be good to have a small test for that :)

I will produce one in the next few days.

@PhilippImhof
Copy link
Member Author

How can black fail and tell me the line no. 5 is too long? It's 44 chars now....

@PhilippImhof
Copy link
Member Author

The lint check is driving me mad. First it complained, because the line was longer than 79 chars. And now it seemingly puts all the stuff on one line again?

image

What length am I supposed to use? @naveen521kk

tests/test_markup.py Outdated Show resolved Hide resolved
Copy link
Member

@naveen521kk naveen521kk left a comment

Choose a reason for hiding this comment

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

LGTM!

@naveen521kk naveen521kk merged commit 69c1013 into ManimCommunity:main Jan 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MarkupText - Invalid Characters
2 participants