Drupal.formatString() doesn't properly replace all the placeholders. This bug was introduced in issue #2182265.

Steps to reproduce:
Try to quick-edit any content, it will show an error ("Could not load the form for Body, either due to a website problem or a network connection problem.
Please try again.").

Small test example is to write Drupal.stringReplace("/x/!aa/!b", {"!aa":1, "!b":2}, null); in webinspector.
Expected result: "/x/1/2"
Actual result: "/x/1/!b"

Problem happens because Drupal.stringReplace() splits the input string into two parts and calls itself recursively with the same keys object. Each such iteration removes one element from the remaining keys array, even if this key isn't found in this part of the string. Following recursions are using one less keys element, which is why they cannot replace some of the placeholders in the original string.

Attached patch fixes the problem by doing the recursion with the copy of the keys array instead.

/Andrejs

CommentFileSizeAuthor
locale-js-plural--1-D8.patch492 bytesandrejsmuzikovs
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nod_’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +JavaScript

That makes sense, thanks.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.x, thanks!

Sweetchuck’s picture

Sorry for this mistake, and @andrejsmuzikovs thank you for the fix.

andrejsmuzikovs’s picture

No problems, and thanks! My first contribution :)

/Andrejs

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.