Skip to content

Commit aa00d38

Browse files
Copilotswissspidy
andcommitted
Support anonymous gists by making username optional in regex
Anonymous gists don't have a username in the URL path (e.g., gist.github.com/1234567890abcdef). Updated regex to make the username segment optional using non-capturing group (?:[^/]+/)? so both user-owned and anonymous gists are supported. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent ff342c9 commit aa00d38

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/WP_CLI/CommandWithUpgrade.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1179,8 +1179,9 @@ private function build_rate_limiting_error_message( $decoded_body ) {
11791179
*/
11801180
protected function get_gist_id_from_url( $url ) {
11811181
// Match gist.github.com URLs but not gist.githubusercontent.com (raw URLs)
1182+
// Supports both user-owned gists (gist.github.com/username/id) and anonymous gists (gist.github.com/id)
11821183
// Gist IDs are hexadecimal strings that can contain both lowercase and uppercase
1183-
if ( preg_match( '#^https?://gist\.github\.com/[^/]+/([a-fA-F0-9]+)/?$#', $url, $matches ) ) {
1184+
if ( preg_match( '#^https?://gist\.github\.com/(?:[^/]+/)?([a-fA-F0-9]+)/?$#', $url, $matches ) ) {
11841185
return $matches[1];
11851186
}
11861187
return null;

0 commit comments

Comments
 (0)