Open aheinzel opened 6 months ago
Also worth noting is that the escaping does not only affect the rewrite conditions and thus delivery of cached files but also cache generation itself. The same method for escaping metacharacters in the cookies is used when assembling the suffix for the cache files, see https://github.com/BoldGrid/w3-total-cache/blob/91e0b97b706e6fe9aa4dabecee9b62f34bafc025/PgCache_ContentGrabber.php#L1264
So in case a regex is used to specify the cookie for a cookie group the group will not be detected when assembling the cache path and thus the content for the accessed URL will be cached as default (no group).
Is it possible that cookie groups do not actually support the use of regex?
Under Settings -> Cache Groups in the section manage cookie groups under the Cookies textarea field it is stated that regex are supported:
However, when using a regex it appears that meta characters are escaped while generating mod_rewrite rewrite conditions, see: https://github.com/BoldGrid/w3-total-cache/blob/91e0b97b706e6fe9aa4dabecee9b62f34bafc025/PgCache_Environment.php#L657
To examplify this issue I created a cache group regtest1 with the following settings:
cookie_.*_prefs=a.*
In return the following rewrite rule/condition was added to my .htaccess file by W3 Total Cache:
In the rule generated all the metacharacters have been escaped. In consequence the condition does not match a request with cookie_1_prefs=a1. See following trace:
When manually adding the same condition without escaping of metacharacters the condition matches.
This issue does not only affect user defined cache groups but also applies to the built in cache group for logged in users, see https://github.com/BoldGrid/w3-total-cache/blob/91e0b97b706e6fe9aa4dabecee9b62f34bafc025/ConfigKeys.php#L720 To match this group the following two lines are added to
.htaccess
But a request with the cookie
wordpress_logged_in_1234
will not be matched by this conditionEnvironment