Skip to content

Commit

Permalink
v2.0 simple code refactor to move comment
Browse files Browse the repository at this point in the history
  • Loading branch information
newbreedofgeek committed Dec 14, 2023
1 parent 1ab7b80 commit e814563
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/requirements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,22 @@ pub trait RequirementsModule: crate::storage::StorageModule {

// Checks whether the URL passed is valid (characters, starts with https://)
fn require_url_is_valid(&self, url: &ManagedBuffer) {
// Define a closure to perform the URL validation
self.require_url_is_adequate_length(url);
let validation_closure = |url_bytes: &[u8]| {
let starts_with: &[u8] = b"https://";

for i in 0..starts_with.len() {
require!(url_bytes[i] == starts_with[i], ERR_NOT_URL);
}

for i in 0..url_bytes.len() {
require!(
url_bytes[i] > 32 && url_bytes[i] < 127,
ERR_URL_INVALID_CHARACTERS
)
}
self.require_url_is_adequate_length(url);

// Define a closure to perform the URL validation
let validation_closure = |url_bytes: &[u8]| {
let starts_with: &[u8] = b"https://";

for i in 0..starts_with.len() {
require!(url_bytes[i] == starts_with[i], ERR_NOT_URL);
}

for i in 0..url_bytes.len() {
require!(
url_bytes[i] > 32 && url_bytes[i] < 127,
ERR_URL_INVALID_CHARACTERS
)
}
};

// Use the with_buffer_contents function to apply the closure
Expand Down

0 comments on commit e814563

Please sign in to comment.