google / google/google-java-format

Unclosed string literal error on regex string

Aperta
#1,253 1 commento 1 reazione 0 assegnatari Vedi su GitHub
Lingua principale
Java
Stelle
6.2k
Fork
937
Merge medio
6m
PR unite (30g)
3

Descrizione

Hello, I found this issue when updating the formatter version in googleapis/java-spanner

```java
package com.example;

final class Test {
// Error: unclosed string literal
String breaks = "'\\d{2}):(\\d{2}):(\\d{2})(\\.\\d{1,9})?)([Zz]|([+-])(\\d{2}):(\\d{2})))|(READ_TIMESTAMP)[\\t";
// Works
String fix = "'\\d{2}):(\\d{2}):(\\d{2})(\\.\\d{1,9})?)([Zz]|([+-])(\\d{2}):(\\d{2})))|(READ_TIMESTAMP)[\u005Ct";
}
```

Produces the following error:
```
hi on] diegomarquezp:java-spanner$ java -jar ~/.library_generation/google-java-format.jar --version
google-java-format: Version 1.26.0
[hi on] diegomarquezp:java-spanner$ java -jar ~/.library_generation/google-java-format.jar test.java
test.java:7:13: error: unclosed string literal
String fix = "'((STRONG)|(MIN_READ_TIMESTAMP)[\\t ]+((\\d{4})-(\\d{2})-(\\d{2})([Tt](\\d{2}):(\\d{2}):(\\d{2})(\\.\\d{1,9})?)([Zz]|([+-])(\\d{2}):(\\d{2})))|(READ_TIMESTAMP)[\u005Ct ]+((\\d{4})-(\\d{2})-(\\d{2})([Tt](\\d{2}):(\\d{2}):( \\d{2})(\\.\\d{1,9})?)([Zz]|([+-])(\\d{2}):(\\d{2})))|(MAX_STALENESS)[\u005Ct ]+((\\d{1,19})(s|ms|us|ns))|(EXACT_STALENESS)[\\t ]+((\\d{1,19})(s|ms|us|ns)))'";
^
[hi on] diegomarquezp:java-spanner$
```

Note that `String fix` doesn't have the error after replacing these two specific double backslashes `\\` with the hexcode version `\u0005C`.

**update**: simplified reproducer code.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.