go-yaml / yaml

YAML support for the Go language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] omit to unset flag 'space_break' in emitterc.go

xl4sh opened this issue · comments

commented

Once the variable is set true due to line break character after space character, is is not set to false forever, even if next line starts.

This is the code of emitterc.go

#1347		} else if is_break(value, i) {
			line_breaks = true
			if i == 0 {
				leading_break = true
			}
			if i+width(value[i]) == len(value) {
				trailing_break = true
			}
			if previous_space {
				space_break = true
			}
			previous_space = false
			previous_break = true
		} else {
			previous_space = false
			previous_break = false
#1363		}

Unmarshal after Marshal example
https://go.dev/play/p/OynW46MUgAb

=== RUN   TestParse
    prog_test.go:20: 
        command: |
          Invoke-Command -Session $Session -ScriptBlock {  // "Invoke-Command -Session $Session -ScriptBlock {<space>\n"
          $a = 1
    prog_test.go:25: command: "Invoke-Command -Session $Session -ScriptBlock { \n$a = 1"
        
    prog_test.go:29: command: |-
            Invoke-Command -Session $Session -ScriptBlock {
            $a = 1
        
--- PASS: TestParse (0.00s)
PASS

Program exited.

Fixing this bug looks easy but I'd like to know the purpose of space_break variable.

issue #908 may have to do with this bug.