varabyte / kobweb-cli

The CLI binary that drives the interactive Kobweb experience. See varabyte/kobweb
Apache License 2.0
10 stars 5 forks source link

Bug: unescaped special characters in visible project name cause `kobweb run` to config error #14

Open EgorBron opened 5 months ago

EgorBron commented 5 months ago

It's not that critical, but I wanted to report it.


While setting up the project with kobweb create, it allows to pass any kind of character to the visible name of the project:

$ kobweb create app/empty
...
? What is the user-visible display title for your project?
> Foo's "Bar\Baz"
...

However, the config is stored in YAML, and it does not allow unescaped quotes and backslashes, leading to a config error when running the app via kobweb run:

$ kobweb run -p foobar/site
✗ A .kobweb folder's `conf.yaml` file seems to have been deleted at some point. This is not expected and Kobweb cannot run without it. Consider restoring your `conf.yaml` file from source control history if possible, or create a new, temporary Kobweb project from scratch and copy its `conf.yaml` file over, modifying it as necessary.

(BTW, the message confused me the first time, and I thought it was a problem with my Linux distribution, but it's not)


So, what causes such issue?

Currently, the code that checks config validity, is just a null check on config content: https://github.com/varabyte/kobweb-cli/blob/0f68aec9562710d2bf3aa588ff2d926cb4388b9d/kobweb/src/main/kotlin/com/varabyte/kobweb/cli/common/KobwebUtils.kt#L52-L55

Which was always null on any parse error. I did a quick check, and it seems to lead to a non-strict YAML parser (not really sure):

https://github.com/varabyte/kobweb/blob/17e25243da037a2c3373cca33969ea97175974a4/common/kobweb-common/src/main/kotlin/com/varabyte/kobweb/project/conf/KobwebConf.kt#L233-L237

A possible solution would be to automatically escape all special symbols and show the user a small warning so they don't try it next time.

bitspittle commented 3 weeks ago

Thank you for reporting and sorry I missed this issue for so long. I'll take a look at it for the next release.