Florian Forster
cade852d47
scanner: Add unit test triggering a panic in unread().
...
For example, the (Go quoted) input "\"\\00" creates the following stack
trace:
```
panic: bytes.Buffer: UnreadRune: previous operation was not a successful ReadRune
goroutine 1 [running]:
github.com/hashicorp/hcl/hcl/scanner.(*Scanner).unread(0xc420090270)
gopath/src/github.com/hashicorp/hcl/hcl/scanner/scanner.go:112 +0x245
github.com/hashicorp/hcl/hcl/scanner.(*Scanner).scanDigits(0xc420090270, 0x0, 0x8, 0x3, 0x5c2005b740)
gopath/src/github.com/hashicorp/hcl/hcl/scanner/scanner.go:557 +0x1ba
github.com/hashicorp/hcl/hcl/scanner.(*Scanner).scanEscape(0xc420090270, 0xc40000005c)
gopath/src/github.com/hashicorp/hcl/hcl/scanner/scanner.go:520 +0x181
github.com/hashicorp/hcl/hcl/scanner.(*Scanner).scanString(0xc420090270)
gopath/src/github.com/hashicorp/hcl/hcl/scanner/scanner.go:504 +0x2c3
github.com/hashicorp/hcl/hcl/scanner.(*Scanner).Scan(0xc420090270, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
gopath/src/github.com/hashicorp/hcl/hcl/scanner/scanner.go:172 +0x509
github.com/hashicorp/hcl/hcl/parser.(*Parser).scan(0xc42005bd18, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
gopath/src/github.com/hashicorp/hcl/hcl/parser/parser.go:448 +0xf4
github.com/hashicorp/hcl/hcl/parser.(*Parser).objectKey(0xc42005bd18, 0x530aa8, 0xc42005bd18, 0xc42005bd18, 0x18, 0x50f980)
gopath/src/github.com/hashicorp/hcl/hcl/parser/parser.go:224 +0xca
github.com/hashicorp/hcl/hcl/parser.(*Parser).objectItem(0xc42005bd18, 0x0, 0x0, 0x0)
gopath/src/github.com/hashicorp/hcl/hcl/parser/parser.go:150 +0xbf
github.com/hashicorp/hcl/hcl/parser.(*Parser).objectList(0xc42005bd18, 0xc42000e000, 0x0, 0x0, 0x0)
gopath/src/github.com/hashicorp/hcl/hcl/parser/parser.go:88 +0x139
github.com/hashicorp/hcl/hcl/parser.(*Parser).Parse(0xc42005bd18, 0xc420090270, 0x200000, 0xc42005bce0)
gopath/src/github.com/hashicorp/hcl/hcl/parser/parser.go:59 +0xf3
github.com/hashicorp/hcl/hcl/parser.Parse(0x7fca1fdd9000, 0x4, 0x200000, 0x8, 0x0, 0x0)
gopath/src/github.com/hashicorp/hcl/hcl/parser/parser.go:46 +0x294
github.com/hashicorp/hcl/hcl/printer.Format(0x7fca1fdd9000, 0x4, 0x200000, 0x0, 0xc42005bef0, 0x464307, 0x4, 0xc42005bed0)
gopath/src/github.com/hashicorp/hcl/hcl/printer/printer.go:53 +0x5b
```
2018-03-20 21:24:50 +01:00
Mitchell Hashimoto
f40e974e75
Merge pull request #240 from octo/scanner-next
...
scanner: Update prevPos even when returning utf8.RuneError.
2018-03-20 13:20:55 -07:00
Mitchell Hashimoto
adef769457
Merge pull request #241 from octo/scanner-null
...
printer, scanner: Don't produce unparsable output.
2018-03-20 13:19:40 -07:00
Florian Forster
ec2ba18997
scanner: Fail if U+E123 is found in input.
...
This (invalid) Unicode codepoint is used by the printer package to fix up
the indentation of generated files. If this codepoint is present in the
input, the package gets confused and removes more than it should,
producing unparsable output.
2018-03-20 20:46:51 +01:00
Florian Forster
a5efd34964
scanner: Report null bytes as errors, even at the end of file.
...
The formatter will append a newline at the end of file, causing the output
of printer.Format() to be invalid.
2018-03-20 20:46:51 +01:00
Florian Forster
a81aa7b5dd
printer: Add unit test of Format() producing unparsable output.
2018-03-20 20:46:51 +01:00
Florian Forster
fdaaf22252
scanner: Update prevPos even when returning utf8.RuneError.
...
The calling code will still call unread(), causing panics.
This fixes the TestScanHeredocRegexpCompile() unit test.
2018-03-20 20:46:20 +01:00
Florian Forster
73fde59edb
scanner: Add unit test triggering a panic in scanHeredoc().
...
```
panic: regexp: Compile("[[:space:]]*<\xc8\\z"): error parsing regexp: invalid UTF-8: `�\z`
goroutine 32 [running]:
testing.tRunner.func1(0xc4200cae10)
/usr/lib/google-golang/src/testing/testing.go:742 +0x29d
panic(0x507a00, 0xc420290690)
/usr/lib/google-golang/src/runtime/panic.go:505 +0x229
regexp.MustCompile(0xc420289e10, 0x10, 0xc420087680)
/usr/lib/google-golang/src/regexp/regexp.go:240 +0x171
github.com/hashicorp/hcl/hcl/scanner.(*Scanner).scanHeredoc(0xc4200878c0)
gopath/src/github.com/hashicorp/hcl/hcl/scanner/scanner.go:444 +0x3a9
github.com/hashicorp/hcl/hcl/scanner.(*Scanner).Scan(0xc4200878c0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
gopath/src/github.com/hashicorp/hcl/hcl/scanner/scanner.go:186 +0x3e5
```
2018-03-20 20:46:20 +01:00
Seth Vargo
b1738d9053
Fix broken formatting directives ( #242 )
...
It looks like Go 1.10 fails these. This makes the build green again.
2018-03-20 14:36:33 -04:00
Seth Vargo
23c074d0ec
Merge pull request #218 from COsorio11/patch-1
...
Fix type
2017-10-17 19:19:29 +01:00
Seth Vargo
6308fb6f2a
Merge pull request #219 from COsorio11/patch-2
...
fix typo
2017-10-17 19:19:22 +01:00
Mitchell Hashimoto
aaf0695c2f
Merge pull request #213 from hashicorp/fix-decodeStruct-data-race
...
Fix data race in decodeStruct
2017-10-17 10:17:50 -07:00
COsorio11
24ca72c351
fix typo
...
begining to beginning
2017-10-17 10:11:56 -07:00
COsorio11
493dc91ef2
Fix type
...
begining to beginning
2017-10-17 10:10:01 -07:00
Davor Kapsa
42e33e2d55
travis: update go versions
2017-10-09 10:47:08 -07:00
Frank Schroeder
42206063bf
Fix data race in decodeStruct
...
Using *reflect.StructField as map key results in a data race. I honestly
do not understand why yet and can only reproduce this in the consul
codebase with high concurrency but this patch fixes it.
The same problem also exists in mitchellh/mapstructure.
2017-09-26 12:36:24 +02:00
Mitchell Hashimoto
68e816d1c7
Merge pull request #210 from hashicorp/decode-number-into-float
...
Decode NUMBER into float32 and float64 fields
2017-09-14 08:46:24 -07:00
Frank Schroeder
3f6a3cf683
Decode NUMBER into float32 and float64 fields
...
This patch decodes a NUMBER value (e.g. "2") into a float32 and float64
field.
2017-09-14 14:57:19 +02:00
Mikael Olenfalk
8f6b1344a9
Return PosError instead of error in more cases
2017-08-25 10:13:36 -07:00
Jelte Fennema
392dba7d90
Support decoding HCL floats into Go float32
2017-05-09 15:53:59 -07:00
James Bardin
a4b07c25de
Merge pull request #173 from hashicorp/jbardin/crlf
...
Remove CRLF line endings
2017-05-04 15:02:34 -04:00
Mitchell Hashimoto
7fa7fff964
Merge pull request #197 from sean-/f-stray-error
...
Return an error instead of printing stray `illegal\n` to stdout.
2017-04-20 16:14:34 -07:00
Sean Chittenden
20ef8cf57f
Return an error instead of printing stray illegal\n
to stdout.
2017-04-20 16:09:49 -07:00
Mitchell Hashimoto
630949a3c5
Merge pull request #190 from hashicorp/b-singleline
...
hcl/printer: singleline objects followed by non-singleline need blank
2017-02-17 08:47:38 -08:00
Mitchell Hashimoto
b943d49ebc
Update .travis.yml
2017-02-17 08:47:33 -08:00
Mitchell Hashimoto
b979c7a8d6
hcl/printer: singleline objects followed by non-singleline need blank
...
Fixes https://github.com/hashicorp/terraform/issues/12017
2017-02-17 08:45:53 -08:00
Mitchell Hashimoto
372e8ddaa1
Merge pull request #186 from hashicorp/b-comments
...
hcl/printer: cleaner handling of standalone comments at end of file
2017-02-01 16:05:34 -08:00
Mitchell Hashimoto
47562ccf19
hcl/printer: cleaner handling of standalone comments at end of file
2017-02-01 16:03:59 -08:00
Mitchell Hashimoto
88e9565e99
Merge pull request #185 from hashicorp/f-list-of-lists
...
hcl/parser: parse list of lists
2017-01-30 13:06:51 -08:00
Mitchell Hashimoto
08c7efd78d
hcl/parser: parse list of lists
2017-01-30 13:05:20 -08:00
Mitchell Hashimoto
db4f076892
Merge pull request #184 from hashicorp/b-singleline-obj
...
hcl/printer: format single line objects to not have newline between
2017-01-24 17:06:35 -08:00
Mitchell Hashimoto
e2dbf84eb0
hcl/printer: format single line objects to not have newline between
...
Fixes #161
See #161 and test cases for examples.
2017-01-24 17:05:35 -08:00
Mitchell Hashimoto
72ac8ca2e6
Merge pull request #183 from hashicorp/b-list-comment
...
hcl/printer: preserve list comment on first line
2017-01-24 16:52:30 -08:00
Mitchell Hashimoto
efcf294794
hcl/printer: preserve list comment on first line
2017-01-24 16:51:14 -08:00
Mitchell Hashimoto
4f21d59dc7
Merge pull request #182 from hashicorp/b-comment
...
hcl/printer: format comments across multiple lines in an object
2017-01-24 16:46:15 -08:00
Mitchell Hashimoto
db65f66984
hcl/printer: format comments across multiple lines in an object
...
https://github.com/hashicorp/terraform/issues/11209
See the TF issue above for an example, and test cases for a fix. This
didn't affect any other formatting tests.
2017-01-24 16:44:23 -08:00
Mitchell Hashimoto
dfbfb1c68d
Merge pull request #181 from hashicorp/b-heredoc-single
...
hcl: print single heredoc elements properly
2017-01-24 16:28:40 -08:00
Mitchell Hashimoto
1bed77586d
hcl: print single heredoc elements properly
2017-01-24 16:26:48 -08:00
Mitchell Hashimoto
8c0b1f045f
hcl/printer: verify list element with one heredoc is formatted properly
2017-01-24 16:19:14 -08:00
Mitchell Hashimoto
39fa3a62ba
Merge pull request #180 from hashicorp/b-bool-list
...
hcl/parser: support bools in lists
2017-01-19 17:07:30 -08:00
Mitchell Hashimoto
e59762bcc7
hcl/parser: support bools in lists
2017-01-19 17:06:02 -08:00
Mitchell Hashimoto
eb6f65b2d7
Merge pull request #177 from hashicorp/b-fmt-heredoc
...
hcl/printer: newline after heredoc items in lists
2017-01-08 16:25:15 -08:00
Mitchell Hashimoto
4f76b0e04a
hcl/printer: newline after heredoc items in lists
2017-01-08 16:24:08 -08:00
Mitchell Hashimoto
e930f8e5fe
hcl/fmtcmd: include filename in error
2017-01-08 16:13:04 -08:00
Mitchell Hashimoto
80e628d796
Merge pull request #176 from theherk/feature/build-on-Go-before-1.7
...
Modify new bytes.ContainsRune to backward compatible bytes.IndexRune
2016-12-15 14:58:39 -08:00
Herkermer Sherwood
f3dd3ed758
Modify new bytes.ContainsRune to backward compatible bytes.IndexRune
2016-12-15 14:49:10 -08:00
James Bardin
dd5495f43c
Fix newlines in test-fixture
...
hcl/parser/test-fixtures/comment.hcl already contained CRLF line
endings. Convert that to unix and remove the extra cariiage returns
from comment_crlf.hcl.
2016-12-01 13:05:58 -05:00
James Bardin
aaca009935
Don't convert windows newlines
...
If the canonical newline is a single LF, don't insert CRLF in tests
2016-12-01 12:10:09 -05:00
James Bardin
a97a4ff95f
No longer preserve CRLF line endings
...
Matching the behavior of Go tooling, we are going to accept "\r\n" line
endings, but standaradize on "\n" being the official format.
Normalize line endings to "\n in the Parse function, so that we
never get stray "\r" characters in the source.
2016-12-01 12:09:33 -05:00
James Bardin
86950618a5
Don't automatically convert to CRLF in AppVeyor
...
We have test files with both types of line endings, leave them as they
are for tests.
2016-12-01 12:09:33 -05:00