TemplateRegexMatcher.getStartRegex sometimes returns a regex that matches with an index before the license start
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Inizia con TemplateRegexMatcher.getStartRegex e riproduci entrambi gli esempi Java dell’issue. Traccia come le sezioni opzionali e le corrispondenze di variabili greedy vengono convertite nella regex iniziale; il lavoro è completato quando gli esempi riportano gli indici di inizio 3 e 2, incluso il comportamento corretto quando sono presenti parti opzionali.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Version 1.1.11
Example 1 greedy regex after optional:
String licenseText = "ab cd text";
String licenseTemplate = "<<beginOptional>>cd<<endOptional>> <<var;name=\"copyright\";original=\"Copyright (c) <year> <copyright holders> \";match=\".{0,5000}\">> text";
TemplateRegexMatcher templateRegexMatcher = new TemplateRegexMatcher(licenseTemplate);
String startRegex = templateRegexMatcher.getStartRegex(25);
System.out.println("start regex: " + startRegex);
Matcher matcher = Pattern.compile(startRegex).matcher(licenseText);
if (matcher.find()) {
System.out.println("start index found: " + matcher.start());
}
Returns
start regex: (?im)(\Qcd\E\s*)?(.{0,5000})\Qtext\E\s*
start index found: 0
but the start index should be 3.
Example 2 greedy regex at start:
String licenseText = "abtext";
String licenseTemplate = "<<var;name=\"copyright\";original=\"Copyright (c) <year> <copyright holders> \";match=\".{0,5000}\">> text";
TemplateRegexMatcher templateRegexMatcher = new TemplateRegexMatcher(licenseTemplate);
String startRegex = templateRegexMatcher.getStartRegex(25);
System.out.println("start regex: " + startRegex);
Matcher matcher = Pattern.compile(startRegex).matcher(licenseText);
if (matcher.find()) {
System.out.println("start index found: " + matcher.start());
}
Returns
start regex: (?im)(.?{0,5000})\Qtext\E\s*
start index found: 1
but the start index should be 2.
.?{0,5000} doesn't seem to work as expected. It is an unusual regex that some online regex websites say is invalid: https://regex101.com/r/l3810b/1, regexr.com/81kfo.
https://www.freeformatter.com/java-regex-tester.html says the regular expression is valid.
I think maybe to fix this you could just offer a method for a regex to find the beginning of the non-optional part. Otherwise a changing the regular expressions in these two cases to something like the following could work
(?im)((\Qcd\E\s*)(.{0,5000})\Qtext\E\s*)|(\Qtext\E\s*)
(?im)\Qtext\E\s*
In the first case if there were multiple optional parts it would get even more complicated to do it correctly.
- Lingua principale
- Java
- Stelle
- 71
- Fork
- 44
- Merge medio
- 16h 22m
- PR unite (30g)
- 9
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di spdx/Spdx-Java-Library
-
question
Difficoltà 5/5 Più di una settimana Idoneità per principianti 30/100
spdx/Spdx-Java-Library#449 ·
-
question
Difficoltà 5/5 Più di una settimana Idoneità per principianti 30/100
spdx/Spdx-Java-Library#398 ·
-
wontfix
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
spdx/Spdx-Java-Library#393 · 2 commenti · 1 reazione ·
-
matching
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
spdx/Spdx-Java-Library#392 · 4 commenti ·
-
enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 30/100
spdx/Spdx-Java-Library#390 · 11 commenti · 1 reazione ·
Tutte le issue di spdx/Spdx-Java-Library
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
floci-io/floci#5425 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
objectionary/eo-graphs#80 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
objectionary/jucs#141 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
-
bug good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
repowise-dev/repowise#3335 ·
I maintainer di solito rispondono entro 1 giorno