-
Notifications
You must be signed in to change notification settings - Fork 162
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
String values don't properly handle unicode escapes #58
Comments
Hi Steve, If you change the code at line 534 in #self.pre_tokenize()
self.data = ''.join(self.decode_data())
self.length = len(self.data) The unicode string will be stored as raw string, not converted to characters. And one more benefit is that the position will also be correct for files containing unicode. I found this when I tried to debug the position error. |
Good discovery, thanks.
Regards,
Steve
From: chenzimin
Sent: Wednesday, February 6, 2019 2:31 AM
To: c2nes/javalang
Cc: Steve Kommrusch; Author
Subject: Re: [c2nes/javalang] String values don't properly handle unicodeescapes (#58)
Hi Steve,
If you comment out this line, https://github.com/c2nes/javalang/blob/7a4af7f5136dd4f4f4b1846b3872f5688429e5db/javalang/tokenizer.py#L489, the unicode string will be stored as raw string, not converted to characters.
And one more benefit is that the position will also be correct for files containing unicode. I found this when I tried to debug the position error.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am using javalang to tokenize files which include Unicode escape sequences. These are correctly tokenized as strings, but the item.value is not handled cleanly. Consider the 2 cases below:
Case 1: builder.append(text, 0, MAX_TEXT).append('\u2026');
Case 2: builder.append(text, 0, MAX_TEXT).append('…');
In both cases, item.value is identical and I get an exception if I try to write the item.value to a file. I can catch the error and successfully print using python like this:
but the python code above prints the same value for Case 1 and 2. I suspect the proper fix is to use raw strings for String token values internal to javalang. Below is an example of raw strings solving the problem.
The text was updated successfully, but these errors were encountered: