Backslashes being removed from struct tag
thijsheijden opened this issue · comments
Thijs van der Heijden commented
I have the following struct tag: jsonschema:"title=Title,minLength=1,maxLength=40,pattern=^[^\\-<>%{}\\[\\]&#\\\\\\\"]+$"
, and upon running golines ${file} -w -m 120
using the Run on Save
extension in VSCode, the tag is changed into jsonschema:"title=title=Title,maxLength=40,pattern=^[^\-<>%{}\[\]&#\\\"]+$"
, turning it into an invalid struct tag.
Arnoldas Grigutis commented
To reproduce the bug, run golines on this file and notice how “pattern” changes.
package main
import "fmt"
type foo struct {
Name string `jsonschema:"pattern=^[^\\-<>%{}\\[\\]&#\\\\\\\"]+$"`
}
func main() {
// The below forces golines to rewrite the file and in doing so it changes the foo.Name field's "pattern"
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa := 1
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb := 1
if aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa+bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb == 2 {
fmt.Println("true")
}
}
Even if the regular expression is invalid, the tool should not try to change it.