We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents b1738d9 + ec2ba18 commit adef769Copy full SHA for adef769
hcl/printer/printer_test.go
@@ -147,3 +147,25 @@ func lineAt(text []byte, offs int) []byte {
147
}
148
return text[offs:i]
149
150
+
151
+// TestFormatParsable ensures that the output of Format() is can be parsed again.
152
+func TestFormatValidOutput(t *testing.T) {
153
+ cases := []string{
154
+ "#\x00",
155
+ "#\ue123t",
156
+ }
157
158
+ for _, c := range cases {
159
+ f, err := Format([]byte(c))
160
+ if err != nil {
161
+ // ignore these failures, not all inputs are valid HCL.
162
+ t.Logf("Format(%q) = %v", c, err)
163
+ continue
164
165
166
+ if _, err := parser.Parse(f); err != nil {
167
+ t.Errorf("Format(%q) = %q; Parse(%q) = %v", c, f, f, err)
168
169
170
171
+}
hcl/scanner/scanner.go
@@ -95,12 +95,16 @@ func (s *Scanner) next() rune {
95
s.srcPos.Column = 0
96
97
98
- // If we see a null character with data left, then that is an error
99
- if ch == '\x00' && s.buf.Len() > 0 {
+ if ch == '\x00' {
100
s.err("unexpected null character (0x00)")
101
return eof
102
103
+ if ch == '\uE123' {
104
+ s.err("unicode code point U+E123 reserved for internal use")
105
+ return utf8.RuneError
106
107
108
// debug
109
// fmt.Printf("ch: %q, offset:column: %d:%d\n", ch, s.srcPos.Offset, s.srcPos.Column)
110
return ch
hcl/scanner/scanner_test.go
@@ -509,9 +509,12 @@ func TestScan_crlf(t *testing.T) {
509
func TestError(t *testing.T) {
510
testError(t, "\x80", "1:1", "illegal UTF-8 encoding", token.ILLEGAL)
511
testError(t, "\xff", "1:1", "illegal UTF-8 encoding", token.ILLEGAL)
512
+ testError(t, "\uE123", "1:1", "unicode code point U+E123 reserved for internal use", token.ILLEGAL)
513
514
testError(t, "ab\x80", "1:3", "illegal UTF-8 encoding", token.IDENT)
515
testError(t, "abc\xff", "1:4", "illegal UTF-8 encoding", token.IDENT)
516
+ testError(t, "ab\x00", "1:3", "unexpected null character (0x00)", token.IDENT)
517
+ testError(t, "ab\x00\n", "1:3", "unexpected null character (0x00)", token.IDENT)
518
519
testError(t, `"ab`+"\x80", "1:4", "illegal UTF-8 encoding", token.STRING)
520
testError(t, `"abc`+"\xff", "1:5", "illegal UTF-8 encoding", token.STRING)
0 commit comments