New issue
Advanced search Search tips

Issue 747142 link

Starred by 1 user

Issue metadata

Status: Archived
Owner: ----
Closed: Jan 10
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

Add linter test for ".replace('"

Project Member Reported by dschuyler@chromium.org, Jul 20 2017

Issue description

In CL https://codereview.chromium.org/2930833004 a quick fix for a bug used blah.replace('foo', 'bar') which was only a partial fix to the issue. This is because blah.replace('foo', 'bar') only replaces the first occurrence of 'foo' in blah. In the interest of avoiding similar issues in the future, consider adding a Lint test on javascript for “.replace(‘“ and advise “.replace(/.../g” instead.
 

Comment 1 by dpa...@chromium.org, Jul 20 2017

Is Blink>Javascript the right component for this? There is no action for the Blink team it seems.

Comment 2 by dpa...@chromium.org, Jul 20 2017

Also, not sure if flagging all usage of replace() to use /g is a good solution. There can be legitimate usages of replace() to only replace the 1st occurrence.

Demanding unit tests for the code that uses replace(), during code review seems more scaleable I think.
Components: -Blink>JavaScript
dpapad@ discussed this further offline.

The goal is to have something automated that advises SWEs about the potential to misunderstand .replace(). That doesn't have to be a linter test, but it needs to be more than having SWEs simply "do better", since the code did have unit tests that didn't cover that case (and the code and unit tests were reviewed by *very* experienced JavaScript SWEs).

We also discussed whether expecting replace() to replace all occurrences would be a common case. I found that searching for why: javascript replace() only replaces the first instance, finds several help forum Q&As. There are 100's of combined upvotes on answers explaining this unexpected behavior. Certainly more research can be done, but there does seem to be an issue here.
Labels: -Pri-1 Pri-3
Summary: Add linter test for ".replace('" (was: [PM nbsp] Add linter test for ".replace('")
This is a not a PM-goal (as I initially thought it would be), so lessening the pri.
Status: Archived (was: Untriaged)
Archiving P3s older than 1 year with no owner or component.

Sign in to add a comment