[Bug]: Editing coordinates crashes or adds a second {{Location}} because the template is found by plain text match

Aperta Adatta ai principianti
#7,464 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
74/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
android, kotlin
Ambito
mobile

Direzione di ricerca

Inizia con CoordinateEditHelper.getFormattedWikiText() e i test unitari menzionati nell’issue, quindi riproduci entrambi i casi: una descrizione che contiene «Location» senza un template e un template {{location scritto in minuscolo. Aggiorna il rilevamento dei template in modo che corrisponda a questi casi ed escluda {{Object location. Il lavoro è completato quando entrambi i casi passano senza arresti anomali o template di posizione duplicati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

CoordinateEditHelper.getFormattedWikiText() decides whether a file already has a {{Location}} template with wikiText.contains("Location"), and then looks for it with indexOf("{{Location"). This goes wrong in two cases:

  1. The word "Location" appears elsewhere, e.g. |description={{en|1=Location: the old harbour}}, but there is no {{Location}} template. Then indexOf("{{Location") is -1 and the coordinate edit crashes with StringIndexOutOfBoundsException: begin -1.
  2. The template is written with a lowercase first letter, {{location|1.0|2.0}}, which MediaWiki accepts. It isn't recognised, so a second {{Location|...}} is added and the file ends up with two location templates.

I reproduced both by calling getFormattedWikiText() with these texts in a unit test.

Fix idea: find the template with a regex that matches {{Location and {{location (but not {{Object location) and use its position, instead of the plain text check. I'd like to work on this, could you assign me?

Lingua principale
Kotlin
Stelle
1.2k
Fork
1.4k
Merge medio
1g 4h
PR unite (30g)
156

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di commons-app/apps-android-commons

Tutte le issue di commons-app/apps-android-commons

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.