Skip to content

Commit 2231add

Browse files
authored
Require component package names/namespace are lowercase (#1505)
Implement WebAssembly/component-model#338
1 parent 076dfc1 commit 2231add

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

crates/wasmparser/src/validator/names.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,9 +627,9 @@ impl<'a> ComponentNameParser<'a> {
627627
// pkgpath ::= <namespace>+ <label> <projection>*
628628
fn pkg_path(&mut self, require_projection: bool) -> Result<()> {
629629
// There must be at least one package namespace
630-
self.take_kebab()?;
630+
self.take_lowercase_kebab()?;
631631
self.expect_str(":")?;
632-
self.take_kebab()?;
632+
self.take_lowercase_kebab()?;
633633

634634
if self
635635
.features
@@ -638,7 +638,7 @@ impl<'a> ComponentNameParser<'a> {
638638
// Take the remaining package namespaces and name
639639
while self.next.starts_with(':') {
640640
self.expect_str(":")?;
641-
self.take_kebab()?;
641+
self.take_lowercase_kebab()?;
642642
}
643643
}
644644

@@ -823,6 +823,17 @@ impl<'a> ComponentNameParser<'a> {
823823
.unwrap_or_else(|| self.expect_kebab())
824824
}
825825

826+
fn take_lowercase_kebab(&mut self) -> Result<&'a KebabStr> {
827+
let kebab = self.take_kebab()?;
828+
if let Some(c) = kebab.chars().find(|c| *c != '-' && !c.is_lowercase()) {
829+
bail!(
830+
self.offset,
831+
"character `{c}` is not lowercase in package name/namespace"
832+
);
833+
}
834+
Ok(kebab)
835+
}
836+
826837
fn expect_kebab(&mut self) -> Result<&'a KebabStr> {
827838
let s = self.take_rest();
828839
self.kebab(s)

tests/local/component-model/naming.wast

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,19 @@
9797
)
9898
"`DOWn` is not in kebab case"
9999
)
100+
101+
(assert_invalid
102+
(component
103+
(instance (import "A:b/c"))
104+
)
105+
"character `A` is not lowercase in package name/namespace"
106+
)
107+
(assert_invalid
108+
(component
109+
(instance (import "a:B/c"))
110+
)
111+
"character `B` is not lowercase in package name/namespace"
112+
)
113+
(component
114+
(instance (import "a:b/c"))
115+
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(component
2+
(type (;0;)
3+
(instance)
4+
)
5+
(import "a:b/c" (instance (;0;) (type 0)))
6+
)

0 commit comments

Comments
 (0)