Skip to content

sanitize version_string we got from the wire - #8582

Open
r10s wants to merge 1 commit into
mainfrom
r10s/sanitize-version-string
Open

sanitize version_string we got from the wire#8582
r10s wants to merge 1 commit into
mainfrom
r10s/sanitize-version-string

Conversation

@r10s

@r10s r10s commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

version_string is meant to be displayed by UI, and comes from the wire.

therefore, as a general precaution, ensure a string that is
regarded as a typical version string. all versions in scope are currently v123.456.789-shortsuffix, where suffix is a-z and mostly unused in production. that is the base. we can adapt if there is really a need, but not for theoretical version strings. as we do not stop processing, things are not bad even if we missed a valid usecase herr.

moreover, if version_string is empty, we skip the candidate - as we cannot display something useful to the user. that little bit of care is expected from relays :)

`version_string` is meant to be displayed by UI, and comes from the wire.

therefore, as a general precaution, convert the string
to smth. that is regarded as a typical version string.
all versions in scope are currently 123.456.789, that is the base.
we can adapt if there is really a need, but not for theoretical version strings -
and as we do not stop processing, things are not that bad even if
we missed a valid usecase.
@r10s
r10s requested review from Hocuri and link2xt August 13, 2026 22:11
@r10s r10s changed the title sanitize version_string we got for the wire sanitize version_string we got from the wire Aug 14, 2026
Comment thread src/appversions.rs
let version = get_app_version(&accounts, "foo", "baz").await?.unwrap();
assert_eq!(version.version_integer, 1337);
assert_eq!(version.version_string, "13.37");
assert_eq!(version.version_string, "13.37"); // spaces are removed by sanizize_version_string()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sanitize

Comment thread src/appversions.rs
Comment on lines +59 to +66
.chars()
.map(|c| {
if matches!(c, 'a'..='z' | '0'..='9' | '.' | '-') {
c
} else {
'-'
}
})

@j-g00da j-g00da Aug 14, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be simplified:

Suggested change
.chars()
.map(|c| {
if matches!(c, 'a'..='z' | '0'..='9' | '.' | '-') {
c
} else {
'-'
}
})
.replace(|c: char| !c.is_alphanumeric() && c != '.', "-")

@Hocuri Hocuri left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once the two comments from hpk and j-g00da are addressed

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

Successfully merging this pull request may close these issues.

4 participants