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

Open Beginner friendly
#7,464 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
74/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
android, kotlin
Domain
mobile

Research direction

Start with CoordinateEditHelper.getFormattedWikiText() and the unit tests mentioned in the issue, then reproduce both cases: a description containing “Location” without a template and a lowercase {{location template. Update the template detection to match those cases while excluding {{Object location. Done when both cases pass without a crash or duplicate location template.

Written by the indexing model from the issue text.

Description

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?

Dominant language
Kotlin
Stars
1.2k
Forks
1.4k
Avg merge
1d 4h
Merged PRs (30d)
156

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from commons-app/apps-android-commons

All issues in commons-app/apps-android-commons

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.