cedaro / satispress

Expose installed WordPress plugins and themes as Composer packages.
508 stars 51 forks source link

Download fails when plugin directory name includes uppercase characters #83

Closed theschmocker closed 5 years ago

theschmocker commented 5 years ago

We have a plugin that we would like to include in our Satispress installation. We ran into an issue, where if the plugin directory contains uppercase characters, any attempt to download it fails with a 404 (from both composer and the Satispress backend). Ex: "eventON". Lowercasing the directory fixes the problem, but we worry that updating will reintroduce it.

The slug from a download request is lowercase, but a package's slug may not be. I hacked together a workaround in the where method of AbstractRepository.

public function where( array $args ): array {
        $args       = $this->parse_args( $args );
        $matches    = [];
        $args_count = count( $args );

        foreach ( $this->all() as $item ) {
            $matched = 0;

            foreach ( $args as $key => $value ) {
                if ( $item[ $key ] && $value === $item[ $key ] ) {
                    $matched++;
-                               }
+               } elseif ( 'slug' === $key ) {
+                   if ( $item[ $key ] && strtolower( $item[ $key ] ) === $value ) {
+                       $matched++;
+                   }
+               }
+           }

            if ( $matched === $args_count ) {
                $matches[] = $item;
            }
        }

        return $matches;
    }

I'm not sure if this is an ideal solution, so I have not created a PR.

bradyvercher commented 5 years ago

Thanks for the report @theschmocker. I looked into this a bit and it appears the problem occurs in the download route handler when sanitizing the slug. sanitize_key() converts characters to lowercase and causes the download to fail.

Let me know if the latest commit doesn't fix this for you.

theschmocker commented 5 years ago

That fixed it. Thanks a lot!