Skip to content

Commit

Permalink
BUGFIX Encoding multibyte characters in custom X-Status HTTP headers …
Browse files Browse the repository at this point in the history
…used in CMS (headers don't allow multibyte data)
  • Loading branch information
chillu committed May 14, 2012
1 parent 45ae246 commit d42ea5a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
8 changes: 4 additions & 4 deletions admin/code/LeftAndMain.php
Expand Up @@ -726,7 +726,7 @@ public function save($data, $form) {
$this->extend('onAfterSave', $record);
$this->setCurrentPageID($record->ID);

$this->response->addHeader('X-Status', _t('LeftAndMain.SAVEDUP'));
$this->response->addHeader('X-Status', rawurlencode(_t('LeftAndMain.SAVEDUP')));
return $this->getResponseNegotiator()->respond($this->request);
}

Expand All @@ -739,7 +739,7 @@ public function delete($data, $form) {

$record->delete();

$this->response->addHeader('X-Status', _t('LeftAndMain.SAVEDUP'));
$this->response->addHeader('X-Status', rawurlencode(_t('LeftAndMain.SAVEDUP')));
return $this->getResponseNegotiator()->respond(
$this->request,
array('currentform' => array($this, 'EmptyForm'))
Expand Down Expand Up @@ -809,7 +809,7 @@ public function savetreenode($request) {
}
}

$this->response->addHeader('X-Status', _t('LeftAndMain.REORGANISATIONSUCCESSFUL', 'Reorganised the site tree successfully.'));
$this->response->addHeader('X-Status', rawurlencode(_t('LeftAndMain.REORGANISATIONSUCCESSFUL', 'Reorganised the site tree successfully.')));
}

// Update sorting
Expand All @@ -830,7 +830,7 @@ public function savetreenode($request) {
}
}

$this->response->addHeader('X-Status', _t('LeftAndMain.REORGANISATIONSUCCESSFUL', 'Reorganised the site tree successfully.'));
$this->response->addHeader('X-Status', rawurlencode(_t('LeftAndMain.REORGANISATIONSUCCESSFUL', 'Reorganised the site tree successfully.')));
}

return Convert::raw2json($statusUpdates);
Expand Down
4 changes: 2 additions & 2 deletions admin/javascript/LeftAndMain.BatchActions.js
Expand Up @@ -246,9 +246,9 @@
// Reset action
self.find(':input[name=Action]').val('').change();

// status message
// status message (decode into UTF-8, HTTP headers don't allow multibyte)
var msg = xmlhttp.getResponseHeader('X-Status');
if(msg) statusMessage(msg, (status == 'success') ? 'good' : 'bad');
if(msg) statusMessage(decodeURIComponent(msg), (status == 'success') ? 'good' : 'bad');
},
success: function(data, status) {
var id, node;
Expand Down
3 changes: 0 additions & 3 deletions admin/javascript/LeftAndMain.Content.js
Expand Up @@ -147,9 +147,6 @@

this.trigger('reloadeditform', {form: form, origData: origData, xmlhttp: xmlhttp});
}

// set status message based on response
var _statusMessage = (xmlhttp.getResponseHeader('X-Status')) ? xmlhttp.getResponseHeader('X-Status') : xmlhttp.statusText;
},

/**
Expand Down
3 changes: 2 additions & 1 deletion admin/javascript/LeftAndMain.js
Expand Up @@ -55,7 +55,8 @@ jQuery.noConflict();

// Show message (but ignore aborted requests)
if(xhr.status !== 0 && msg && $.inArray(msg, ignoredMessages)) {
statusMessage(msg, msgType);
// Decode into UTF-8, HTTP headers don't allow multibyte
statusMessage(decodeURIComponent(msg), msgType);
}
});

Expand Down

0 comments on commit d42ea5a

Please sign in to comment.