Skip to content

import/path: issue title #73061

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

Closed
freddyisaac opened this issue Mar 26, 2025 · 5 comments
Closed

import/path: issue title #73061

freddyisaac opened this issue Mar 26, 2025 · 5 comments
Labels
BugReport Issues describing a possible bug in the Go implementation.

Comments

@freddyisaac
Copy link

freddyisaac commented Mar 26, 2025

Go version

go version 1.24.1

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/freddy.isaac/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/freddy.isaac/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1218015667=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/me/projects/ratel/go.mod'
GOMODCACHE='/home/me/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/me/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/bin/go1.24.1'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/me/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/bin/go1.24.1/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.1'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

html/template package seems to handle quoted curly braces differently if the pair are on a single line or a split line. Although to be honest I am not sure if maybe the javascript violates any standards

https://go.dev/play/p/bIASN-hohyL

Hopefully this demonstrates the behaviour

I will include the code here also

package main

import (
	"html/template"
	"log"
)

func main() {
	script1 := `<script>
		function foo(str) {
                return str.indexOf("{{") === 0 &&
                    str.lastIndexOf("}}") === str.length - 2;
            }
	</script>`

	_, err := template.New("").Parse(script1)
	if err != nil {
		log.Printf("script1 Parse error %v", err)
	} else {
		log.Printf("script1 ok")
	}

	script2 := `<script>
		function foo(str) {
                return str.indexOf("{{") === 0 && str.lastIndexOf("}}") === str.length - 2;
            }
	</script>`

	_, err = template.New("").Parse(script2)
	if err != nil {
		log.Printf("script2 Parse error %v", err)
	} else {
		log.Printf("script2 ok")
	}
}

What did you see happen?

2009/11/10 23:00:00 script1 Parse error template: :3: unterminated quoted string
2009/11/10 23:00:00 script2 ok

The first script that has brace pairs on distinct lines error off whereas the second example succeeds

What did you expect to see?

I would have hoped that both examples were parsed in a similar manner - but I could be mistaken :)

@seankhliao
Copy link
Member

neither will do what you want, but the error makes sense since you can have string literals in actions {{ "..." }}, but like go double quoted strings, they cannot span multiple lines.

closing as working as intended.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Mar 26, 2025
@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Mar 26, 2025
@freddyisaac
Copy link
Author

freddyisaac commented Mar 26, 2025

not sure what you mean by what I want
I think that they should not act differently

Exactly what do you think I want it to do ?

@randall77
Copy link
Contributor

{{ marks the start of an action. So you have a line with

return str.indexOf("{{...someAction...

Which does not have a balancing end quote.
(Action starts/ends are not suppressed by double quotes.)

@freddyisaac
Copy link
Author

freddyisaac commented Mar 27, 2025

yes - thx
oddly the code wasn't mine originally - I have recommeded that the input is changed to be

indexOf({{"{{"}})

Which is I believe is what the code was trying to do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation.
Projects
None yet
Development

No branches or pull requests

4 participants