Skip to content

Commit f1b5ce9

Browse files
committed
Use stable Rust
1 parent ae8eab8 commit f1b5ce9

File tree

4 files changed

+13
-61
lines changed

4 files changed

+13
-61
lines changed

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nightly
1+
stable

src/core.rs

Lines changed: 11 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl Core {
134134

135135
buffer.replace_range(query as usize..fragment as usize, "");
136136
}
137-
(None, Some(_) | None, None) => {
137+
(None, _, None) => {
138138
// do nothing
139139
}
140140
}
@@ -190,7 +190,13 @@ impl Core {
190190
this.parse_query(&mut input)?;
191191
this.parse_fragment(&mut input)?;
192192

193-
this.check_invariants(data.as_ref(), false)?;
193+
if this.method(data.as_ref()).is_empty() {
194+
return Err(Error::InvalidMethodName);
195+
}
196+
197+
if this.method_id(data.as_ref()).is_empty() {
198+
return Err(Error::InvalidMethodId);
199+
}
194200

195201
Ok(this)
196202
}
@@ -203,8 +209,6 @@ impl Core {
203209
this.parse_query(&mut input)?;
204210
this.parse_fragment(&mut input)?;
205211

206-
this.check_invariants(data.as_ref(), true)?;
207-
208212
Ok(this)
209213
}
210214

@@ -253,7 +257,7 @@ impl Core {
253257

254258
loop {
255259
match input.peek() {
256-
Some('/' | '?' | '#') | None => break,
260+
Some('/') | Some('?') | Some('#') | None => break,
257261
Some(ch) if char_method_id(ch) => {}
258262
_ => return Err(Error::InvalidMethodId),
259263
}
@@ -267,13 +271,13 @@ impl Core {
267271
fn parse_path(&mut self, input: &mut Input) -> Result<()> {
268272
self.path = input.index();
269273

270-
if matches!(input.peek(), Some('?' | '#') | None) {
274+
if matches!(input.peek(), Some('?') | Some('#') | None) {
271275
return Ok(());
272276
}
273277

274278
loop {
275279
match input.peek() {
276-
Some('?' | '#') | None => break,
280+
Some('?') | Some('#') | None => break,
277281
Some(ch) if char_path(ch) => {}
278282
_ => return Err(Error::InvalidPath),
279283
}
@@ -335,58 +339,6 @@ impl Core {
335339

336340
Ok(())
337341
}
338-
339-
fn _is_valid_method(&self, data: &str) -> bool {
340-
let value: &str = self.method(data);
341-
!value.is_empty() && value.chars().all(char_method)
342-
}
343-
344-
fn _is_valid_method_id(&self, data: &str) -> bool {
345-
let value: &str = self.method_id(data);
346-
!value.is_empty() && value.chars().all(char_method_id)
347-
}
348-
349-
fn _is_valid_path(&self, data: &str) -> bool {
350-
self.path(data).chars().all(char_path)
351-
}
352-
353-
fn _is_valid_query(&self, data: &str) -> bool {
354-
self
355-
.query(data)
356-
.map(|data| data.chars().all(char_query))
357-
.unwrap_or(true)
358-
}
359-
360-
fn _is_valid_fragment(&self, data: &str) -> bool {
361-
self
362-
.fragment(data)
363-
.map(|data| data.chars().all(char_fragment))
364-
.unwrap_or(true)
365-
}
366-
367-
fn check_invariants(&self, data: &str, relative: bool) -> Result<()> {
368-
if !relative && !self._is_valid_method(data) {
369-
return Err(Error::InvalidMethodName);
370-
}
371-
372-
if !relative && !self._is_valid_method_id(data) {
373-
return Err(Error::InvalidMethodId);
374-
}
375-
376-
if !self._is_valid_path(data) {
377-
return Err(Error::InvalidPath);
378-
}
379-
380-
if !self._is_valid_query(data) {
381-
return Err(Error::InvalidQuery);
382-
}
383-
384-
if !self._is_valid_fragment(data) {
385-
return Err(Error::InvalidQuery);
386-
}
387-
388-
Ok(())
389-
}
390342
}
391343

392344
// =============================================================================

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//!
77
//! - [DID Core](https://www.w3.org/TR/did-core/)
88
//!
9-
#![feature(or_patterns)]
109
#![no_std]
1110

1211
#[cfg(not(feature = "alloc"))]

tests/parse.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ fn test_parse_valid_method_id() {
3030
#[test]
3131
#[rustfmt::skip]
3232
fn test_parse_invalid_method_id() {
33+
assert!(DID::parse("did:method:").is_err());
3334
assert!(DID::parse("did:method:: :").is_err());
3435
assert!(DID::parse("did:method: - - -").is_err());
3536
assert!(DID::parse("did:method:*****").is_err());

0 commit comments

Comments
 (0)