Skip to content

Conversation

@nicolasmure
Copy link
Contributor

Hello,

This PR fixes the followiong metadata parsing error :

$mask = 'X-Object-Meta-';
$header = 'X-Object-Meta-Manufacturer';

echo ltrim($header, $mask); // "nufacturer"

See live example here.

Actually, ltrim does not replaces by the whole string but uses chars in the given mask instead, and stops when it encounter a char which is not in the mask.

@haphan
Copy link
Collaborator

haphan commented Jan 16, 2018

Nice catch @nicolasmure! Surprisingly no one has reported this issue.

Performance wise, for this simple job, do you think we can just simply use substr instead of regex?

$name = substr($header, strlen(static::METADATA_PREFIX));

Did a small benchmark

haphan@hpbookpro:~/Projects/openstack$ php bench.php
running 1000 * 1000 iteration
regex took 1.05065107346 ms to complete
substr took 0.200830221176 ms to complete

@haphan haphan self-assigned this Jan 16, 2018
@haphan haphan added the bug label Jan 16, 2018
@nicolasmure
Copy link
Contributor Author

Sure @haphan :) I updated the code.

@haphan haphan merged commit 69db575 into php-opencloud:master Jan 16, 2018
@haphan
Copy link
Collaborator

haphan commented Jan 16, 2018

thanks @nicolasmure 🎸

@nicolasmure nicolasmure deleted the fix/metadata-parsing branch January 16, 2018 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants