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

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

Open
EgorBron opened this issue Apr 16, 2024 · 2 comments
Assignees

Comments

@EgorBron
Copy link

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:

fun assertKobwebConfIn(kobwebFolder: KobwebFolder): KobwebConf {
return KobwebConfFile(kobwebFolder).content
?: throw KobwebException("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.")
}

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:/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 bitspittle self-assigned this Sep 12, 2024
@bitspittle
Copy link
Contributor

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

bitspittle added a commit that referenced this issue Oct 19, 2024
It turns out that if a conf.yaml file cannot be parsed, we were interpreting that
as the file not existing, which caused us to deliver a confusing error message.

Now, we distinguish between the two cases and issue an appropriate error based
on whether the file was deleted or just not parsable.

Bug #14
bitspittle added a commit that referenced this issue Oct 19, 2024
... which can be useful when importing user strings in conf.yaml files,
etc.

Bug #14
@bitspittle
Copy link
Contributor

Hello! It has been a while but finally had some time to work on the Kobweb CLI for a bit.

Two points of good news in relation to this issue...

  1. I updated the utility method you linked to (assertKobwebConfIn(folder)) and I now print out a more sensible error. If the conf.yaml file can be found, I'll encourage users to open it up and check the syntax of the file.

  2. I added a utility method to the Kobweb CLI for escaping YAML text, which will let me fix this more completely in the future.


So, the slightly bad news..... The YAML escaping method will only be available to users using 0.9.17 (which, at the moment, I'm aiming to release on Monday or Tuesday of next week). So even though in theory I can insert the method into the kobweb template to fix this issue after that point, I would need to bump the minimum version of the app template to 0.9.17 as well.

If it was some random example template that had the issue, I would just go ahead and do this. However, the app template is so central to getting up and running with Kobweb, I'm always careful about making "breaking" changes. At this point, I'll wait 6 months after releasing 0.9.17 before updating the app template and fixing this once and for all.

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

2 participants