Skip to content

Commit 5618f6d

Browse files
authored
feat: relax plugin identifier requirements to alphanumeric and - (#8856)
closes #8820
1 parent 11a5816 commit 5618f6d

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'tauri': 'patch:enhance'
3+
'tauri-utils': 'patch:enhance'
4+
---
5+
6+
Relax requirements on plugin's identifiers to be alphanumeric and `-` instead of only lower alpha and `-`.

core/tauri-utils/src/acl/identifier.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ enum ValidByte {
7373
}
7474

7575
impl ValidByte {
76-
fn lower_alpha(byte: u8) -> Option<Self> {
77-
byte.is_ascii_lowercase().then_some(Self::Byte(byte))
76+
fn alpha_numeric(byte: u8) -> Option<Self> {
77+
byte.is_ascii_alphanumeric().then_some(Self::Byte(byte))
7878
}
7979

80-
fn lower_alpha_hyphen(byte: u8) -> Option<Self> {
81-
matches!(byte, b'a'..=b'z' | b'-').then_some(Self::Byte(byte))
80+
fn alpha_numeric_hyphen(byte: u8) -> Option<Self> {
81+
(byte.is_ascii_alphanumeric() || byte == b'-').then_some(Self::Byte(byte))
8282
}
8383

8484
fn next(&self, next: u8) -> Option<ValidByte> {
@@ -87,9 +87,9 @@ impl ValidByte {
8787
(ValidByte::Separator, b'-') => None,
8888

8989
(_, IDENTIFIER_SEPARATOR) => Some(ValidByte::Separator),
90-
(ValidByte::Separator, next) => ValidByte::lower_alpha(next),
91-
(ValidByte::Byte(b'-'), next) => ValidByte::lower_alpha(next),
92-
(ValidByte::Byte(_), next) => ValidByte::lower_alpha_hyphen(next),
90+
(ValidByte::Separator, next) => ValidByte::alpha_numeric(next),
91+
(ValidByte::Byte(b'-'), next) => ValidByte::alpha_numeric(next),
92+
(ValidByte::Byte(_), next) => ValidByte::alpha_numeric_hyphen(next),
9393
}
9494
}
9595
}
@@ -149,7 +149,7 @@ impl TryFrom<String> for Identifier {
149149
// grab the first byte only before parsing the rest
150150
let mut prev = bytes
151151
.next()
152-
.and_then(ValidByte::lower_alpha)
152+
.and_then(ValidByte::alpha_numeric)
153153
.ok_or(Self::Error::InvalidFormat)?;
154154

155155
let mut idx = 0;
@@ -222,6 +222,8 @@ mod tests {
222222
#[test]
223223
fn format() {
224224
assert!(ident("prefix:base").is_ok());
225+
assert!(ident("prefix3:base").is_ok());
226+
assert!(ident("preFix:base").is_ok());
225227

226228
// bad
227229
assert!(ident("tauri-plugin-prefix:base").is_err());

0 commit comments

Comments
 (0)