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

text/template/parse: Pos is wrong in FieldNodes like .A.B.C #43388

Open
pjweinb opened this issue Dec 26, 2020 · 1 comment
Open

text/template/parse: Pos is wrong in FieldNodes like .A.B.C #43388

pjweinb opened this issue Dec 26, 2020 · 1 comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@pjweinb
Copy link

pjweinb commented Dec 26, 2020

$ go version
go version go1.15.6 darwin/amd64

The template string

{{if .A.B.C.D}}{{printf .Z.Y.X.W}}
{{.Moo.N.P}}{{end}}

parses as


ListNode at 0:0, 2 children
. IfNode at 0:5
. . BranchNode at 0:5
. . Pipe. PipeNode at 0:5, 0 vars, 1 cmds
. . Pipe. . CommandNode at 0:5, 1 children
. . Pipe. . . FieldNode at 0:7, [A B C D]
. . List. ListNode at 0:15, 3 children
. . List. . ActionNode at 0:17
. . List. . . PipeNode at 0:17, 0 vars, 1 cmds
. . List. . . . CommandNode at 0:17, 2 children
. . List. . . . . IdentifierNode at 0:17
. . List. . . . . FieldNode at 0:26, [Z Y X W]
. . List. . TextNode at 1:1, len 1
. . List. . ActionNode at 1:2
. . List. . . PipeNode at 1:2, 0 vars, 1 cmds
. . List. . . . CommandNode at 1:2, 1 children
. . List. . . . . FieldNode at 1:6, [Moo N P]
. TextNode at 3:1, len 1

The offsets in the FieldNodes are after the first identifier. That is, in {{.Moo.N.P}} on line 1, the offset is 6, not 2. (And the same for the other FieldNodes.) If there is only one identifier in the FieldNode, then the offset is correct.

@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 5, 2021
@toothrot toothrot added this to the Backlog milestone Jan 5, 2021
@toothrot
Copy link
Contributor

toothrot commented Jan 5, 2021

/cc @robpike @mvdan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

2 participants