3

Using the Android app, whenever one edits an answer containing links by adding one or more extra links, all pre-existing links and their displayed text are replaced by the last link in the list (computed before the edit). Yes this bug description is a mouthful. For simplicity, here is how to reproduce the bug:

  1. Create an answer with two or more links
  2. Wait for the edit grace period to elapse
  3. Edit the post by adding one more link

Here is a sample post from Travel.SE where this happened. Below is a screenshot of the relevant edit history showing the effects of this bug:

link edit bug android app

I've had this happen to me a few times already (I do a lot of answering and editing via the app). This bug is quite annoying because it heavily modifies the post content, and since the revision list isn't visible via the app one must wait to log in from a browser to fix the modifications.

I'm using Android 4.4.4 on a Google Nexus 5, the installed SE app version is 1.0.63.

0

1 Answer 1

4

This will be fixed in 1.0.84.

This was caused my a mistranslation of JavaScript's String.prototype.replace(/.../g, func) into Java, causing later finds to replace earlier matches.

We're now using the following two methods to perform these replacements:

private interface Replacer {
    String replace(Matcher matcher);
}

// This is a generalization of http://stackoverflow.com/a/4742293/860000, acting as an equivalent to String.prototype(/pattern/g, replacer.replace)
private String replaceAll(String input, Pattern pattern, Replacer replacer) {
    StringBuffer output = new StringBuffer();
    Matcher matcher = pattern.matcher(input);
    while (matcher.find()) {
        matcher.appendReplacement(output, replacer.replace(matcher));
    }
    matcher.appendTail(output);
    return output.toString();
}

// Same as above but without the global flag.
private String replaceFirst(String input, Pattern pattern, Replacer replacer) {
    StringBuffer output = new StringBuffer();
    Matcher matcher = pattern.matcher(input);
    if (matcher.find()) {
        matcher.appendReplacement(output, replacer.replace(matcher));
    }
    matcher.appendTail(output);
    return output.toString();
}
1
  • Great stuff. Will wait for the update before accepting this as an answer.
    – JoErNanO
    Mar 18, 2016 at 1:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .