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

panic after warning of missing semi-colon for css @import #1803

Closed
sbfaulkner opened this issue Nov 25, 2021 · 1 comment
Closed

panic after warning of missing semi-colon for css @import #1803

sbfaulkner opened this issue Nov 25, 2021 · 1 comment

Comments

@sbfaulkner
Copy link
Contributor

sbfaulkner commented Nov 25, 2021

The following CSS causes a panic when esbuild tries to process it...

@import url("fonts.css")

.one {
	background: url("one.jpg");
}

.two {
	background: url("two.jpg");
}

the panic…

$ bin/esbuild --loader=css --minify <style.css
 > style.css:9:1: warning: Expected ";"
    9 │ }
      ╵  ^

panic: runtime error: index out of range [1] with length 1

goroutine 10 [running]:
github.com/evanw/esbuild/internal/css_printer.(*printer).printTokens(0xc0000bf420, {0xc000222100, 0x4, 0x7301040000}, {0x10, 0x0})
	/Users/sbfaulkner/src/github.com/evanw/esbuild/internal/css_printer/css_printer.go:694 +0xcb9
github.com/evanw/esbuild/internal/css_printer.(*printer).printTokens(0xc0000bf420, {0xc000224000, 0x6, 0x0}, {0x0, 0x0})
	/Users/sbfaulkner/src/github.com/evanw/esbuild/internal/css_printer/css_printer.go:704 +0xa5e
github.com/evanw/esbuild/internal/css_printer.(*printer).printRule(0xc0000bf420, {{0x0}, {0x1512c88, 0xc000020840}}, 0x0, 0x0)
	/Users/sbfaulkner/src/github.com/evanw/esbuild/internal/css_printer/css_printer.go:104 +0x1058
github.com/evanw/esbuild/internal/css_printer.Print({{0xc00003c840, 0x1, 0x1}, {0xc00000e9a8, 0x1, 0x1}, {{0x0, 0x0}, {{0x0}, 0x0}}, ...}, ...)
	/Users/sbfaulkner/src/github.com/evanw/esbuild/internal/css_printer/css_printer.go:54 +0x305
github.com/evanw/esbuild/internal/bundler.(*linkerContext).generateChunkCSS(0xc00017b040, {0xc0000dd080, 0x1, 0x1}, 0x0, 0xc00002b850)
	/Users/sbfaulkner/src/github.com/evanw/esbuild/internal/bundler/linker.go:4882 +0xe38
created by github.com/evanw/esbuild/internal/bundler.(*linkerContext).generateChunksInParallel
	/Users/sbfaulkner/src/github.com/evanw/esbuild/internal/bundler/linker.go:356 +0x46f

NOTE: our actual failure is in a service that invokes the go pkg directly -- not the CLI

@sbfaulkner sbfaulkner changed the title panic after warning of missing semi-colon panic after warning of missing semi-colon for css @import Nov 25, 2021
@sbfaulkner
Copy link
Contributor Author

sbfaulkner commented Nov 25, 2021

NOTE: this is actually two problems in one...

  1. since it panics in a goroutine, we have no way to prevent this from taking down the service that is using it -- ideally, the pkg would recover and provide us with an error of some sort even in cases like this
  2. parsing of conditions for an @import is too lax, resulting in the "conditions" including the remaining css (ie. to eof)... https://github.com/evanw/esbuild/blob/master/internal/css_parser/css_parser.go#L650-L652

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant