Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@leogama
Copy link
Contributor

@leogama leogama commented Jun 26, 2021

Fixes fail obtained when a syntax error interrupts the parsing at a
Unicode character and, as a consequence, the parsed content returned
by getParseData(source_file) includes a truncated UTF-8 multibyte
representation of that character (which is invalid). See the GitHub
issue discussion (#815) for details.

The proposed solution merely "coerces" the getParseData's text
column to what it is supposed to be according to its documentation.

An alternative would be to actually fix the table before use:

content[!content$terminal, "text"] <- ""

Fixes fail obtained when a syntax error interrupts the parsing at a
Unicode character and, as a consequence, the parsed content returned
by 'getParseData(source_file)' includes an incomplete UTF-8 multibyte
representation of that character (which is invalid). See the GitHub
issue discussion for details.

The proposed solution merely "coerces" the getParseData's 'text'
column to what it is supposed to be according to its documentation.

An alternative would be to actually fix the table before use:
> content[!content$terminal, "text"] <- ""
@AshesITR
Copy link
Collaborator

Thanks for providing a fix.
Can you add a regression test for this?
I think your MWE is perfectly fine for that.

@leogama
Copy link
Contributor Author

leogama commented Jun 27, 2021

Done. I didn't know exactly how to test that a specific error doesn't occur, but it seems extensive enough like this.

Note: I had to force-push because, when I ran the unit test with devtools::check(), it modified some files (NAMESPACE and man/linters.Rd) and I committed them by mistake.

@MichaelChirico
Copy link
Collaborator

I didn't know exactly how to test that a specific error doesn't occur

expect_error(expr, NA) is exactly the right approach IINM

it modified some files (NAMESPACE and man/linters.Rd) and I committed them by mistake.

FYI that shouldn't be an issue, just rm the files in another commit and push to the same branch (I see you are on master on your fork, even on a fork you should try putting PRs in branches). When we do Squash+Merge here into main, that temporary issue will be resolved.

Comment on lines 84 to 89
tmp <- tempfile()
on.exit(unlink(tmp), add = TRUE)
writeLines("y <- x \U2013 42", tmp) # Unicode en-dash
content <- expect_error(get_source_expressions(tmp), NA)
expect_equal(content$error$message, "unexpected input")
expect_equal(content$error$column_number, 8L)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure if possible, but have you tried using with_content_to_parse() used in the other tests?

Copy link
Contributor Author

@leogama leogama Jun 28, 2021

Choose a reason for hiding this comment

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

I took a look at it, but it seemed that with_content_to_parse() itself would fail with the bug. And as it doesn't use the expect family of functions internally, the error would not be well formatted. I didn't verify it though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did some experiments with the tests just now. The error generated by with_content_to_parse() ends well formatted anyway by testthat. So in principle we could use it, but it doesn't expose the error item from get_source_expressions() result. I'm sending an alternative version of the tests with a modification to that helper function.

@AshesITR
Copy link
Collaborator

Looks good now. Please add a NEWS bullet, then we can merge.

@AshesITR AshesITR merged commit 387b939 into r-lib:master Jun 30, 2021
@leogama
Copy link
Contributor Author

leogama commented Jun 30, 2021

Thank you for your time and attention. 😉

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.

3 participants