Hello,

the provider of my Drupal 6 (latest, greatest) site doesn't allow clean urls (costs extra :-( ) so I can't use them.
For security reasons I want to /need to set the download method to "private".
This results in media URLs that containt the "?q=" portion that tells drupal the action gets replaced by the code in

function _swftools_get_flashvars_string(&$flashvars) {
  foreach ($flashvars AS $var => $value) {
    $flashvars[$var] = str_replace(array('&', '=', '?'), array('%26', '%3D', '%3F'), $value);
  }

from ?q= to %3Fq%3D.
However, some code (I haven't figured out which) will replace this again to %253Fq%253D so the player cannot find the file anymore.

If I comment out the replacements in function _swftools_get_flashvars_string(&$flashvars) everything works fine, since the second replacement takes care of the ?q= to %3Fq%3D conversion anyways. So I wonder, why the replacement in this function is needed anymore, or where I'll break the code elsewhere if I modify this.

Tilman
but I wonder what else will break then.

Comments

skybow’s picture

[Update]
I just did some more debugging. Here I what I got:

function _swftools_get_flashvars_string(&$flashvars) {

  foreach ($flashvars AS $var => $value) {
    $flashvars[$var] = str_replace(array('&', '=', '?'), array('%26', '%3D', '%3F'), $value);
  }
  $encoded = drupal_query_string_encode($flashvars);

  // '#' seems to encode as %2523, reverse this, using a more robust hex prefix..
  $encoded = str_replace('%2523', '0x', $encoded);

  // Fix encoding per #181998#comment-882293
  $encoded = str_replace('%3A', ':', $encoded);
  $encoded = str_replace('%252F', '/', $encoded);

//>> Added code to comensate for double replacements as proposed here
  $encoded = str_replace('%253Fq%253D', '%3Fq%3D', $encoded);
//<<
  
  return $encoded;
}

The double replacements takes place in drupal_query_string_encode($flashvars).
I added the following line to compensate this:

  $encoded = str_replace('%253Fq%253D', '%3Fq%3D', $encoded);

Could someone please check on this?

mafet’s picture

been looking for this fix as well thanx skybow... it works on my test site as well....