Prevents redirect URLs that have canonical URLs longer than 255 chars from being written to the database as their canonical. Redirecting URLs will instead be saved to the database as given.

The reason for this is that table 'file' column 'url' is a VARCHAR(255) in MySQL and it silently truncates URLs longer than 255 characters, breaking the url.

The proper fix for this is to improve this column, making its type TEXT, but there are no database changes for 0.8.x, so this is the next best thing for data integrity. A migration script for 0.9.x could be written to audit the database checking for redirects and updating these urls to their proper canonical url.
This commit is contained in:
Brett Taylor 2009-08-12 16:00:46 +12:00 committed by Brenda Wallace
parent 2260cf20f5
commit 3243612e76

View File

@ -95,7 +95,8 @@ class File extends Memcached_DataObject
if (empty($file_redir)) { if (empty($file_redir)) {
$redir_data = File_redirection::where($given_url); $redir_data = File_redirection::where($given_url);
$redir_url = $redir_data['url']; $redir_url = $redir_data['url'];
if ($redir_url === $given_url) { // TODO: max field length
if ($redir_url === $given_url || strlen($redir_url) > 255) {
$x = File::saveNew($redir_data, $given_url); $x = File::saveNew($redir_data, $given_url);
$file_id = $x->id; $file_id = $x->id;
} else { } else {