diff --git a/sites/all/modules/unl/unl_migration.php b/sites/all/modules/unl/unl_migration.php
index 2f157ec652084a936e409fc337c9b91201d32208..14eacf959a81982eb82f03e89975aef0e1f8cf9f 100644
--- a/sites/all/modules/unl/unl_migration.php
+++ b/sites/all/modules/unl/unl_migration.php
@@ -477,8 +477,12 @@ class Unl_Migration_Tool
             while (strpos($parts['path'], '/./') !== FALSE) {
                 $parts['path'] = strtr($parts['path'], array('/./', '/'));
             }
+            $i = 0;
             while (strpos($parts['path'], '/../') !== FALSE) {
                 $parts['path'] = preg_replace('/\\/[^\\/]*\\/\\.\\.\\//', '/', $parts['path']);
+                $parts['path'] = preg_replace('/^\\/\\.\\.\\//', '/', $parts['path']);
+                // Prevent infinite loops if we get some crazy url.
+                if ($i++ > 100) exit;
             }
         }