Skip to content

Implement error handling for (raw-)unicode-escape codec#694

Merged
slozier merged 3 commits intoIronLanguages:masterfrom
BCSharp:unicode_escape_errors
Dec 7, 2019
Merged

Implement error handling for (raw-)unicode-escape codec#694
slozier merged 3 commits intoIronLanguages:masterfrom
BCSharp:unicode_escape_errors

Conversation

@BCSharp
Copy link
Copy Markdown
Member

@BCSharp BCSharp commented Dec 5, 2019

Similarities to escape_decode turned out to be smaller than I expected.

Comment thread Src/IronPython/Runtime/LiteralParser.cs Outdated
void handleError(int start, int end, string reason) {
bytesData ??= data is byte[] ba ? new Bytes(ba) : Bytes.Empty;

if (errorHandler == null || start >= bytesData.Count) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If data is not byte[] it will ignore errorHandler and always throw (since bytesData.Count == 0). Is this the expected behavior? If we expect errorHandler to always be null with char[] then I would add a guard (Debug.Assert or NotImplementedException) at the top of the method.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, it was the intended behaviour. The current implementation assumes errorHandler to be always default with char[], since currently there is no need for a non-default handler in such case. If in the future this assumption is no longer valid, handleError has to be updated. I agree that a guard with NotImplementedException is better than a silent ignore.

Copy link
Copy Markdown
Contributor

@slozier slozier left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thanks.

@slozier slozier merged commit 7848ca5 into IronLanguages:master Dec 7, 2019
@BCSharp BCSharp deleted the unicode_escape_errors branch December 7, 2019 02:41
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.

2 participants