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

String() should not mutate object #206

Merged
merged 1 commit into from
Mar 1, 2019

Conversation

Gattermeier
Copy link
Contributor

String() mutating the object can cause problems of a doubly query escaped location string. For instance in this example:

cfg := mysql.LoadConfigFromEnv()
log.Println(cfg)

db, err := cfg.DB()
if err != nil {
	panic(err)
}

String() called by the logger will mutate m.Location with query escape. The subsequent String() call via cfg.DB() will lead to the doubly query escaped string. If there is no specific reason as to why String() should have these side effects it might be good not to mutate the object?

cc @bajh

fsouza
fsouza previously approved these changes Feb 26, 2019
@fsouza fsouza dismissed their stale review February 26, 2019 22:42

taking another look

Copy link
Contributor

@fsouza fsouza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change looks good. Can you add tests?

@coveralls
Copy link

Coverage Status

Coverage remained the same at 51.665% when pulling f67a293 on Gattermeier:string-mutation into accd7fe on NYTimes:master.

Copy link
Contributor

@jprobinson jprobinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔇

@jprobinson jprobinson merged commit f435d7b into nytimes:master Mar 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants