rlespinasse/github-slug-action

Bug: `SLUG_URL` can end with a hyphen

timonrey opened this issue ยท 8 comments

Describe the bug
We're using the slug action to generate preview site URLs from git branch names. The slug is used as a subdomain (or sub-subdomain) pointing to the respective deployment. That works pretty well, mainly thanks to your quick response the last time. Thank you again for that! ๐Ÿ™Œ๐Ÿผ
But now we ran into another issue.
We are using the SLUG_URL to create the subdomain and slug-maxlength to adjust the length of the slug to our needs.
We noticed that sometimes, when our branch name is too long and the slug length is being adjusted (or trimmed to the right length) that it can happen that the slug url is ending with an hyphen, which is not a valid hostname in the URL. That gives us an error when we try to create the subdomains.
If I understand the documentation correctly, the trailing - should be removed from the slug. But I guess this is not covered when using the slug-maxlength configuration. ๐Ÿค”

To Reproduce

  • Use a long string with hyphens in between words.
  • Use SLUG_URL with slug-maxlength to create a slug out of the string that is shorter than the original string
  • Try to find the right length of either the string or the maxlength to truncate the string that it ends with an hyphen

Expected behavior
The SLUG_URL should never end with a hyphen.

Screenshots
As you can see, we tried to use the SLUG_URL (our branch name) as subdomain. And in this particular case, the branch name was truncated to the configured length and ended with a hyphen.
image (1)

Additional context
Thank you very much for the quick support you gave us so far! We hope we can help you with this contribution :)

So I assume you only need to do step 3d and 4d after shortening the length again:
https://github.com/rlespinasse/slugify-value/blob/v1.x/slugify.sh#L39-L54

PS: it's not vercel specific, that is just our hosting provider today. The constraint to not have a hyphen at the end is generic in the DNS spec : https://en.wikipedia.org/wiki/Hostname#Syntax

@timonrey the 4d step is now plan to be done after the reduce to be compliant with the slug definition and the DNS spec

๐ŸŽ‰ This issue has been resolved in version 4.2.5 ๐ŸŽ‰

The release is available on GitHub release

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€

@timonrey @nkuehn this new release should do

@rlespinasse Thank you for the quick fix! ๐Ÿ™Œ๐Ÿผ

๐ŸŽ‰ This issue has been resolved in version 3.6.1 ๐ŸŽ‰

The release is available on GitHub release

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€