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
many: validate title #6196
many: validate title #6196
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, reflects the discussions we had. Error messages reflect the same structure as the ones for the other checks. Just a minor comment that could be ignored.
// replacing the last rune with an ellipsis if necessary. If N is less | ||
// than 1 it's treated as a 1. | ||
func ElliptRight(str string, n int) string { | ||
if n < 1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe if n > 1 default to the last rune in that string? And return the original size
@@ -182,3 +183,18 @@ func CommaSeparatedList(str string) []string { | |||
} | |||
return filtered | |||
} | |||
|
|||
// ElliptRight returns a string that is at most n runes long, | |||
// replacing the last rune with an ellipsis if necessary. If N is less |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uppercase N, should be n
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with question about "..." on dumb terminals (aka linux console)
info.EditedTitle = d.Title.Clean() | ||
|
||
// https://forum.snapcraft.io/t/title-length-in-snapcraft-yaml-snap-yaml/8625/10 | ||
info.EditedTitle = strutil.ElliptRight(d.Title.Clean(), 40) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sanity check: stratal.ElliptRight uses runes, not bytes, right?
} | ||
|
||
// this is expensive; look into a cheaper way maybe sometime | ||
return string([]rune(str)[:n-1]) + "…" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes it does :) +1
} | ||
|
||
// this is expensive; look into a cheaper way maybe sometime | ||
return string([]rune(str)[:n-1]) + "…" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will we have terminal issues with the fancy unicode version of "..."?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a'ight. On the default linux console (on Ubuntu) that one works. If it's got a different font loaded maybe not 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meant to +1 the last time.
for _, s := range []string{ | ||
"xx", // boringest ASCII | ||
"🐧🐧", // len("🐧🐧") == 8 | ||
"á", // á (combining) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one counts as two codepoints?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it is using a followed by a combining acute accent. It would be one code point after normalisation to form NFC (canonical decomposition followed by canonical composition).
See https://www.unicode.org/reports/tr15/#Norm_Forms for more info
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. This was because I just came from talking with wgrant about graphemes vs codepoints (where if we're counting graphemes, combining characters have width 0, meaning you could get a megabyte into a description and it have length 1...)
Three commits for your consideration:
strutil.ElliptRight
(need I say more?)snap pack
as well as install etc (but the review tools rejected titles altogether until really recently so that's ok).relevant forum topic.