diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-18 01:57:02 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-18 01:57:02 +0900 |
| commit | fed0a6e7ac361af9b963c1f62411b1a85478230c (patch) | |
| tree | 5cde64a24845c761890fbcbe05e0d702f1ec8df7 /crates/shirabe/src/util/remote_filesystem.rs | |
| parent | e093b2be1c333e67c96aebb0a5291bea9ae3d6db (diff) | |
| download | php-shirabe-fed0a6e7ac361af9b963c1f62411b1a85478230c.tar.gz php-shirabe-fed0a6e7ac361af9b963c1f62411b1a85478230c.tar.zst php-shirabe-fed0a6e7ac361af9b963c1f62411b1a85478230c.zip | |
refactor(preg): add preg_is_match for existence-only call sites
The capture groups were discarded at 162 of the preg_match call sites,
which only tested the Option. They now call preg_is_match, which lets the
regex engine skip capture tracking.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/util/remote_filesystem.rs')
| -rw-r--r-- | crates/shirabe/src/util/remote_filesystem.rs | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/crates/shirabe/src/util/remote_filesystem.rs b/crates/shirabe/src/util/remote_filesystem.rs index a7901567..b584d722 100644 --- a/crates/shirabe/src/util/remote_filesystem.rs +++ b/crates/shirabe/src/util/remote_filesystem.rs @@ -19,8 +19,8 @@ use shirabe_php_shim::{ STREAM_NOTIFY_PROGRESS, array_replace_recursive, base64_encode, explode, extension_loaded, file_get_contents, file_get_contents5, file_put_contents, filter_var_boolean, gethostbyname, http_clear_last_response_headers, http_get_last_response_headers, ini_get, json_decode_assoc, - parse_url, php_regex, preg_match, preg_quote, preg_replace, strpos, strtolower, strtr, substr, - trim, zlib_decode, + parse_url, php_regex, preg_is_match, preg_match, preg_quote, preg_replace, strpos, strtolower, + strtr, substr, trim, zlib_decode, }; /// Result of `RemoteFilesystem::get` — string content, `true` (for copy), or `false`. @@ -159,7 +159,7 @@ impl RemoteFilesystem { pub fn find_status_message(&self, headers: &[String]) -> Option<String> { let mut value: Option<String> = None; for header in headers { - if preg_match(php_regex!("{^HTTP/\\S+ \\d+}i"), header).is_some() { + if preg_is_match(php_regex!("{^HTTP/\\S+ \\d+}i"), header) { value = Some(header.clone()); } } @@ -285,12 +285,10 @@ impl RemoteFilesystem { crate::io::DEBUG, ); - if (preg_match( + if (!preg_is_match( php_regex!("{^http://(repo\\.)?packagist\\.org/p/}"), &file_url, - ) - .is_none() - || (strpos(&file_url, "$").is_none() && strpos(&file_url, "%24").is_none())) + ) || (strpos(&file_url, "$").is_none() && strpos(&file_url, "%24").is_none())) && !degraded_packagist { let _ = self.config.borrow_mut().prohibit_url_by_config( @@ -474,11 +472,10 @@ impl RemoteFilesystem { None, ) != ".zip") && content_type.is_some() - && preg_match( + && preg_is_match( php_regex!("{^text/html\\b}i"), content_type.as_deref().unwrap_or(""), - ) - .is_some(); + ); if bitbucket_login_match { result = None; if retry_auth_failure { |
