diff --git a/pathauto.inc b/pathauto.inc
index 42290ca..fe4b2a5 100644
--- a/pathauto.inc
+++ b/pathauto.inc
@@ -260,21 +260,20 @@ function _pathauto_clean_separators($string, $separator = NULL) {
 
   $output = $string;
 
-  // Clean duplicate or trailing separators.
   if (strlen($separator)) {
-    // Escape the separator.
+    // Trim any leading or trailing separators.
+    $output = trim($output, $separator);
+
+    // Escape the separator for use in regular expressions.
     $seppattern = preg_quote($separator, '/');
 
-    // Trim any leading or trailing separators.
-    $output = preg_replace("/^$seppattern+|$seppattern+$/", '', $output);
+    // Replace multiple separators with a single one.
+    $output = preg_replace("/$seppattern+/", $separator, $output);
 
     // Replace trailing separators around slashes.
     if ($separator !== '/') {
-      $output = preg_replace("/$seppattern+\/|\/$seppattern+/", "/", $output);
+      $output = preg_replace("/\/+$seppattern\/+|$seppattern\/+|\/+$seppattern/", "/", $output);
     }
-
-    // Replace multiple separators with a single one.
-    $output = preg_replace("/$seppattern+/", $separator, $output);
   }
 
   return $output;
@@ -304,12 +303,15 @@ function pathauto_clean_alias($alias) {
 
   $output = $alias;
 
+  // Trim duplicate, leading, and trailing separators. Do this before cleaning
+  // back-slashes since a pattern like "[token1]/[token2]-[token3]/[token4]"
+  // could end up like "value1/-/value2" and if back-slashes were cleaned first
+  // this would result in a duplicate black-slash.
+  $output = _pathauto_clean_separators($output);
+
   // Trim duplicate, leading, and trailing back-slashes.
   $output = _pathauto_clean_separators($output, '/');
 
-  // Trim duplicate, leading, and trailing separators.
-  $output = _pathauto_clean_separators($output);
-
   // Shorten to a logical place based on word boundaries.
   $output = truncate_utf8($output, $cache['maxlength'], TRUE);
 
diff --git a/pathauto.test b/pathauto.test
index 6fa096e..bbe2033 100644
--- a/pathauto.test
+++ b/pathauto.test
@@ -193,6 +193,23 @@ class PathautoUnitTestCase extends PathautoTestHelper {
   }
 
   /**
+   * Test pathauto_clean_alias().
+   */
+  function testCleanAlias() {
+    $tests = array();
+    $tests['one/two/three'] = 'one/two/three';
+    $tests['/one/two/three/'] = 'one/two/three';
+    $tests['one//two///three'] = 'one/two/three';
+    $tests['one/two--three/-/--/-/--/four---five'] = 'one/two-three/four-five';
+    $tests['one/-//three--/four'] = 'one/three/four';
+    foreach ($tests as $input => $expected) {
+      $output = pathauto_clean_alias($input);
+      $this->assertEqual($output, $expected, t("pathauto_clean_alias('@input') expected '@expected', actual '@output'", array('@input' => $input, '@expected' => $expected, '@output' => $output)));
+    }
+
+  }
+
+  /**
    * Test pathauto_path_delete_multiple().
    */
   function testPathDeleteMultiple() {
