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

Sad sad panda when formatting code containing a regex ("^\s$") #541

Closed
marcwrobel opened this issue Jun 20, 2022 · 3 comments · Fixed by #543
Closed

Sad sad panda when formatting code containing a regex ("^\s$") #541

marcwrobel opened this issue Jun 20, 2022 · 3 comments · Fixed by #543
Labels
area: bug 🐛 Something isn't working $$ bug-bounty $$ https://www.jhipster.tech/bug-bounties/ $100 https://www.jhipster.tech/bug-bounties/

Comments

@marcwrobel
Copy link

When formatting a java file that contains the following code with prettier-java 1.6.2 (prettier 2.3.1), I have got a lexing error :

import java.util.regex.Pattern;

public class Test {

  public static final String REGEX = "^\s$";

}

The error is :

$ npx prettier --check Test.java 
Checking formatting...
Test.java[error] Test.java: Error: Sad sad panda, lexing errors detected in line: 5, column: 38!
[error] unexpected character: ->"<- at offset: 91, skipped 1 characters.
[error]     at Object.parse (/tmp/test/node_modules/java-parser/src/index.js:18:11)
[error]     at Object.parse (/tmp/test/node_modules/prettier-plugin-java/dist/parser.js:4:26)
[error]     at Object.parse$a [as parse] (/tmp/test/node_modules/prettier/index.js:13652:19)
[error]     at coreFormat (/tmp/test/node_modules/prettier/index.js:15183:16)
[error]     at formatWithCursor$1 (/tmp/test/node_modules/prettier/index.js:15423:14)
[error]     at Object.formatWithCursor (/tmp/test/node_modules/prettier/index.js:60171:12)
[error]     at format$1 (/tmp/test/node_modules/prettier/bin-prettier.js:16640:21)
[error]     at Object.formatFiles$1 [as formatFiles] (/tmp/test/node_modules/prettier/bin-prettier.js:16754:22)
[error]     at async main (/tmp/test/node_modules/prettier/bin-prettier.js:18616:5)
[error]     at async Object.run (/tmp/test/node_modules/prettier/bin-prettier.js:18559:5)
All matched files use Prettier code style!
@marcwrobel
Copy link
Author

Interestingly, there is no issue if I change the regex to "^\\s$".

@clementdessoude
Copy link
Contributor

Hi @marcwrobel !

Thank you for reporting this ! Looks like we forgot the escaped space from the available escaped sequences. Should be good with #543 !

@clementdessoude clementdessoude added the area: bug 🐛 Something isn't working label Jul 3, 2022
@pascalgrimaud pascalgrimaud added $100 https://www.jhipster.tech/bug-bounties/ $$ bug-bounty $$ https://www.jhipster.tech/bug-bounties/ labels Jul 3, 2022
@pascalgrimaud
Copy link
Member

Adding a bounty as it's a bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: bug 🐛 Something isn't working $$ bug-bounty $$ https://www.jhipster.tech/bug-bounties/ $100 https://www.jhipster.tech/bug-bounties/
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants