Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strings: Replacer fails at beginning of string #6659

Closed
robpike opened this issue Oct 24, 2013 · 5 comments
Closed

strings: Replacer fails at beginning of string #6659

robpike opened this issue Oct 24, 2013 · 5 comments

Comments

@robpike
Copy link
Contributor

robpike commented Oct 24, 2013

package main

import(
    "fmt"
    "strings"
)

func main(){
    fmt.Println(strings.NewReplacer("Hello", "").Replace("Hellox"))
    fmt.Println(strings.NewReplacer("Hello", "").Replace("xHellox"))
}

Prints

Hellox
xx
@bradfitz
Copy link
Contributor

Comment 1:

Broken starting at:
changeset:   14462:0a0a751f0b74
user:        Eric Roshan-Eisner <eric.d.eisner@gmail.com>
date:        Fri Sep 28 12:34:18 2012 +1000
summary:     strings: implement a faster single-string Replacer
Work-around fix:
diff -r 7ebbddd21330 src/pkg/strings/replace.go
--- a/src/pkg/strings/replace.go    Thu Oct 24 10:13:23 2013 -0700
+++ b/src/pkg/strings/replace.go    Thu Oct 24 15:06:56 2013 -0700
@@ -34,7 +34,7 @@
    }
 
    if len(oldnew) == 2 && len(oldnew[0]) > 1 {
-       return &Replacer{r: makeSingleStringReplacer(oldnew[0], oldnew[1])}
+//     return &Replacer{r: makeSingleStringReplacer(oldnew[0], oldnew[1])}
    }
 
Looking into it.

@robpike
Copy link
Contributor Author

robpike commented Oct 24, 2013

Comment 2:

Issue #6660 has been merged into this issue.

@bradfitz
Copy link
Contributor

Comment 3:

Sent https://golang.org/cl/16880043

Status changed to Started.

@bradfitz
Copy link
Contributor

Comment 4:

This issue was closed by revision 2d6a139.

Status changed to Fixed.

@adg
Copy link
Contributor

adg commented Nov 1, 2013

Comment 5:

This issue was closed by revision 0883b7d7a008.

adg added a commit that referenced this issue May 11, 2015
««« CL 16880043 / 0eb6508d3e88
strings: fix Replacer bug with prefix matches

singleStringReplacer had a bug where if a string was replaced
at the beginning and no output had yet been produced into the
temp buffer before matching ended, an invalid nil check (used
as a proxy for having matched anything) meant it always
returned its input.

Fixes #6659

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/16880043
»»»

R=golang-dev
CC=golang-dev
https://golang.org/cl/20570044
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants