Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Fix encoding issue, especially on Windows:
Browse files Browse the repository at this point in the history
 - Parameters passed via url in rest api gets mangled because of urldecode(), make sure to re-apply toUTF8()
 - Once decoded, we must make sure to apply the correct encoding before inserting / searching the DB.
  • Loading branch information
cdujeu committed Nov 5, 2015
1 parent 99bf8e4 commit 71a8e44
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions core/src/core/classes/class.AJXP_Controller.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public static function findRestActionAndApply($actionName, $path)
if (count($paramValues) < count($paramNames)) {
$paramNames = array_slice($paramNames, 0, count($paramValues));
}
$paramValues = array_map(array("SystemTextEncoding", "toUTF8"), $paramValues);
$httpVars = array_merge($_GET, $_POST, array_combine($paramNames, $paramValues));
return self::findActionAndApply($actionName, $httpVars, $_FILES, $action);

Expand Down
5 changes: 4 additions & 1 deletion core/src/plugins/authfront.keystore/class.KeystoreAuthFrontend.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ function tryToLogUser(&$httpVars, $isLast = false){
$private = $data["PRIVATE"];
$explode = explode("?", $_SERVER["REQUEST_URI"]);
$server_uri = rtrim(array_shift($explode), "/");
$server_uri = implode("/", array_map("rawurlencode", array_map("urldecode", explode("/", $server_uri))));
$decoded = array_map("urldecode", explode("/", $server_uri));
$decoded = array_map(array("SystemTextEncoding", "toUTF8"), $decoded);
$decoded = array_map("rawurlencode", $decoded);
$server_uri = implode("/", $decoded);
$server_uri = str_replace("~", "%7E", $server_uri);
//$this->logDebug(__FUNCTION__, "Decoded URI is ".$server_uri);
list($nonce, $hash) = explode(":", $this->detectVar($httpVars, "auth_hash"));
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/feed.sql/class.AJXP_SqlFeedStore.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function persistEvent($hookName, $data, $repositoryId, $repositoryScope,
$userGroup,
($repositoryScope !== false ? $repositoryScope : "ALL"),
serialize($data),
($node!=null ? $node->getUrl():'')
($node!=null ? SystemTextEncoding::toUTF8($node->getUrl()):'')
);
} catch (DibiException $e) {
$this->logError("DibiException", "trying to persist event", $e->getMessage());
Expand Down Expand Up @@ -192,7 +192,7 @@ public function persistAlert(AJXP_Notification $notif)
$userId,
$repositoryId,
serialize($notif),
($notif->getNode()!=null ? $notif->getNode()->getUrl():'')
($notif->getNode()!=null ? SystemTextEncoding::toUTF8($notif->getNode()->getUrl()):'')
);
} catch (DibiException $e) {
$this->logError("DibiException", "trying to persist alert", $e->getMessage());
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/meta.filehasher/class.FileHasher.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public function switchActions($actionName, $httpVars, $fileVars)
if (!$stat || !is_readable($node->getUrl())) {
print '{}';
} else {
if($node->isLeaf()) {
if(is_file($node->getUrl())) {
if(isSet($_SERVER["HTTP_RANGE"])){
$fullSize = floatval($stat['size']);
$ranges = explode('=', $_SERVER["HTTP_RANGE"]);
Expand Down Expand Up @@ -223,7 +223,7 @@ public function switchActions($actionName, $httpVars, $fileVars)
$stat[13] = $stat["hash"] = $hash;
$stat = json_encode($stat);
}
print json_encode($path).':'.$stat . (($index < count($files) -1) ? "," : "");
print json_encode(SystemTextEncoding::toUTF8($path)).':'.$stat . (($index < count($files) -1) ? "," : "");
}
print '}';
}
Expand Down
12 changes: 6 additions & 6 deletions core/src/plugins/meta.syncable/class.ChangesTracker.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -498,14 +498,14 @@ public function updateNodesIndex($oldNode = null, $newNode = null, $copy = false
$repoId = $this->computeIdentifier($oldNode->getRepository(), $oldNode->getUser());
// DELETE
$this->logDebug('DELETE', $oldNode->getUrl());
dibi::query("DELETE FROM [ajxp_index] WHERE [node_path] LIKE %like~ AND [repository_identifier] = %s", $oldNode->getPath(), $repoId);
dibi::query("DELETE FROM [ajxp_index] WHERE [node_path] LIKE %like~ AND [repository_identifier] = %s", SystemTextEncoding::toUTF8($oldNode->getPath()), $repoId);
} else if ($oldNode == null || $copy) {
// CREATE
$stat = stat($newNode->getUrl());
$newNode->setLeaf(!($stat['mode'] & 040000));
$this->logDebug('INSERT', $newNode->getUrl());
dibi::query("INSERT INTO [ajxp_index]", array(
"node_path" => $newNode->getPath(),
"node_path" => SystemTextEncoding::toUTF8($newNode->getPath()),
"bytesize" => $stat["size"],
"mtime" => $stat["mtime"],
"md5" => $newNode->isLeaf()? md5_file($newNode->getUrl()):"directory",
Expand All @@ -523,7 +523,7 @@ public function updateNodesIndex($oldNode = null, $newNode = null, $copy = false
"bytesize" => $stat["size"],
"mtime" => $stat["mtime"],
"md5" => md5_file($newNode->getUrl())
), "WHERE [node_path] = %s AND [repository_identifier] = %s", $oldNode->getPath(), $repoId);
), "WHERE [node_path] = %s AND [repository_identifier] = %s", SystemTextEncoding::toUTF8($oldNode->getPath()), $repoId);
try{
$rowCount = dibi::getAffectedRows();
if($rowCount === 0){
Expand All @@ -538,8 +538,8 @@ public function updateNodesIndex($oldNode = null, $newNode = null, $copy = false
if ($newNode->isLeaf()) {
$this->logDebug('UPDATE LEAF PATH', $newNode->getUrl());
dibi::query("UPDATE [ajxp_index] SET ", array(
"node_path" => $newNode->getPath(),
), "WHERE [node_path] = %s AND [repository_identifier] = %s", $oldNode->getPath(), $repoId);
"node_path" => SystemTextEncoding::toUTF8($newNode->getPath()),
), "WHERE [node_path] = %s AND [repository_identifier] = %s", SystemTextEncoding::toUTF8($oldNode->getPath()), $repoId);
try{
$rowCount = dibi::getAffectedRows();
if($rowCount === 0){
Expand All @@ -552,7 +552,7 @@ public function updateNodesIndex($oldNode = null, $newNode = null, $copy = false
dibi::query("UPDATE [ajxp_index] SET [node_path]=REPLACE( REPLACE(CONCAT('$$$',[node_path]), CONCAT('$$$', %s), CONCAT('$$$', %s)) , '$$$', '') ",
$oldNode->getPath(),
$newNode->getPath()
, "WHERE [node_path] LIKE %like~ AND [repository_identifier] = %s", $oldNode->getPath(), $repoId);
, "WHERE [node_path] LIKE %like~ AND [repository_identifier] = %s", SystemTextEncoding::toUTF8($oldNode->getPath()), $repoId);
try{
$rowCount = dibi::getAffectedRows();
if($rowCount === 0){
Expand Down

0 comments on commit 71a8e44

Please sign in to comment.