eduardoboucas / staticman

💪 User-generated content for Git-powered websites
https://staticman.net
MIT License
2.41k stars 534 forks source link

When the slug is malformed, the error message cannot be parsed because it is not valid JSON #434

Open jamesmortensen opened 2 years ago

jamesmortensen commented 2 years ago

I wanted to get the full path in my slug, so I added a '/' between "post" and the last part of the URL. The error I see in the console is:

error message = path contains a malformed path component: {"resource":"Commit","field":"path","code":"invalid"}
SyntaxError: Unexpected token p in JSON at position 0
    at JSON.parse (<anonymous>)
    at /Users/james/Dev/hugo/staticman/lib/GitHub.js:114:38
    at processTicksAndRejections (internal/process/task_queues.js:95:5)

I added the log statement on GitHub.js line 112 to see why the JSON.parse(message) was not working properly. I think the code may need to be modified to split the message apart from the JSON object so the JSON object can be properly parsed. Hope this helps.

To replicate, use this for your slug <input type="hidden" name="options[slug]" value="{{ replaceRE "/$" "$1" $.RelPermalink }}">

I recognize what I'm trying to do may not be correct, but this issue is about the error handling part. Hope this helps.