Stash icon indicating copy to clipboard operation
Stash copied to clipboard

getItem($key) - shouldn't you be trimming whitespace from the key as well as forward slashes?

Open exts opened this issue 7 years ago • 4 comments

eg.: trim($key, '/ ') Line: 107

Because you can't trust the developer to do that every time when the library is expecting a certain type of string.

$key = " some/key"; would be considered an malformed string going through that method, though it's not always easily caught.

exts avatar Oct 24 '16 20:10 exts

I agree with spaces but not forward slashes.

design1online avatar Oct 13 '17 14:10 design1online

@design1online the reason I said forward slashes because of how Stash deals with forward slashes and automatically grouping arrays. There's really no reason for a cache key to start or end with a forward slash as well.

I've never seen someone write keys like this:

  • user/1/
  • /user/1/
  • /user/1

There's no reason to write cache keys in stash like that at all. If you can give me a use case i'd be glad for you to give me a use case where it's appropriate to write any cache keys like that especially when the next line is an explode:

$key = explode('/', $keyString);

exts avatar Oct 13 '17 16:10 exts

I use keys like that because I create keys based on the classname.

design1online avatar Oct 13 '17 17:10 design1online

@design1online even when you use them based off class names, there's no reason to have forward slashes starting or ending in the key string.

namespace/subnamespace/classname

Anyways my concern with this issue is because Stash does not do checks for empty strings coming from forward slashes which causes problems when they explode a forward slash string and the key is empty.

//stash/should/break here

exts avatar Oct 16 '17 19:10 exts