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

many: validate title #6196

Merged
merged 3 commits into from Nov 26, 2018
Merged

many: validate title #6196

merged 3 commits into from Nov 26, 2018

Conversation

chipaca
Copy link
Contributor

@chipaca chipaca commented Nov 22, 2018

Three commits for your consideration:

  1. strutil.ElliptRight (need I say more?)
  2. ellipt titles coming from the store (in json), both for v1 and v2 paths, to 40 codepoints.
  3. reject as invalid snaps that have titles >40 codepoints. This affects snap pack as well as install etc (but the review tools rejected titles altogether until really recently so that's ok).

relevant forum topic.

Copy link
Contributor

@sergiusens sergiusens left a 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 {
Copy link
Contributor

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
Copy link
Contributor

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

@zyga zyga changed the title Validate title many: validate title Nov 23, 2018
Copy link
Collaborator

@zyga zyga left a 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)
Copy link
Collaborator

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]) + "…"
Copy link
Collaborator

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]) + "…"
Copy link
Collaborator

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 "..."?

Copy link
Contributor Author

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 🤷‍♂️

Copy link
Collaborator

@zyga zyga left a 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)
Copy link
Contributor

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?

Copy link
Collaborator

@zyga zyga Nov 23, 2018

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

Copy link
Contributor Author

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...)

@chipaca chipaca merged commit 202d164 into snapcore:master Nov 26, 2018
@chipaca chipaca deleted the validate-title branch November 29, 2018 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants