Skip to content

Commit

Permalink
Adding a trailing slash to the rewrite base.
Browse files Browse the repository at this point in the history
Allows for analytics to correctly group the pages independantly of the querystring.

Closes #83
  • Loading branch information
Zoramite committed Oct 19, 2011
1 parent e8cc242 commit 4bef93c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
16 changes: 7 additions & 9 deletions cf-compendium/inc/resource/utility/urlRewrite.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,21 @@ component extends="cf-compendium.inc.resource.utility.url" {
arguments.options.start = reReplace(arguments.options.start, '[/]*$', '');
}

// Add a starting slash to the rewrite
if( left(currentLocation[arguments.options.rewriteBase], 1) != '/' ) {
currentLocation[arguments.options.rewriteBase] = '/' & currentLocation[arguments.options.rewriteBase];
}

// Add a trailing slash to the rewrite
if( right(currentLocation[arguments.options.rewriteBase], 1) != '/' ) {
currentLocation[arguments.options.rewriteBase] &= '/';
}

arguments.options.start &= currentLocation[arguments.options.rewriteBase];

arguments.options.keys = listDeleteAt(arguments.options.keys, locate);
}

try {
return super.__get(argumentCollection = arguments);
} catch(any e) {
writeDump(var = currentLocation, label = 'Rewrite currentlocation');
writeDump(var = arguments.options.keys, label = 'Rewrite arguments.options.keys');
writeDump(var = variables.locations, label = 'Rewrite variables.locations');
writeDump(e);
abort;
}
return super.__get(argumentCollection = arguments);
}
}
12 changes: 6 additions & 6 deletions test/inc/resource/utility/urlRewriteGetShouldTest.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ component extends="mxunit.framework.TestCase" {
variables.theUrl.setALocation('chicken', 'awesome');
variables.theUrl.setALocation('_base', '/total/coolness');

assertEquals('/total/coolness?chicken=awesome', variables.theUrl.getALocation());
assertEquals('/total/coolness/?chicken=awesome', variables.theUrl.getALocation());
}

public void function testWithBaseOnly() {
variables.theUrl.setALocation('_base', '/total/coolness');

assertEquals('/total/coolness?', variables.theUrl.getALocation());
assertEquals('/total/coolness/?', variables.theUrl.getALocation());
}

public void function testWithBaseTrailingSlash() {
Expand All @@ -31,7 +31,7 @@ component extends="mxunit.framework.TestCase" {

variables.theUrl.setALocation('_test', '/tastes')

assertEquals('/tastes?chicken=awesome', variables.theUrl.getALocation(false, { rewriteBase = '_test' }));
assertEquals('/tastes/?chicken=awesome', variables.theUrl.getALocation(false, { rewriteBase = '_test' }));
}

public void function testWithoutBaseValue() {
Expand All @@ -45,20 +45,20 @@ component extends="mxunit.framework.TestCase" {
variables.theUrl.setALocation('beef', 'super');
variables.theUrl.setALocation('_base', '/total/coolness');

assertEquals('/admin/total/coolness?beef=super', variables.theUrl.getALocation(false, { start = '/admin' }));
assertEquals('/admin/total/coolness/?beef=super', variables.theUrl.getALocation(false, { start = '/admin' }));
}

public void function testWithStart() {
variables.theUrl.setALocation('chicken', 'awesome');
variables.theUrl.setALocation('_base', '/total/coolness');

assertEquals('/admin/total/coolness?chicken=awesome', variables.theUrl.getALocation(false, { start = '/admin' }));
assertEquals('/admin/total/coolness/?chicken=awesome', variables.theUrl.getALocation(false, { start = '/admin' }));
}

public void function testWithStartTrailingSlash() {
variables.theUrl.setALocation('chicken', 'awesome');
variables.theUrl.setALocation('_base', '/total/coolness');

assertEquals('/admin/total/coolness?chicken=awesome', variables.theUrl.getALocation(false, { start = '/admin/' }));
assertEquals('/admin/total/coolness/?chicken=awesome', variables.theUrl.getALocation(false, { start = '/admin/' }));
}
}

0 comments on commit 4bef93c

Please sign in to comment.