Index: includes/path.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/path.inc,v
retrieving revision 1.19
diff -u -p -r1.19 path.inc
--- includes/path.inc	4 Nov 2007 16:42:45 -0000	1.19
+++ includes/path.inc	25 May 2008 14:26:30 -0000
@@ -64,10 +64,15 @@ function drupal_lookup_path($action, $pa
       if (isset($map[$path_language][$path])) {
         return $map[$path_language][$path];
       }
+      $dst = '';
       // Get the most fitting result falling back with alias without language
-      $alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s' AND language IN('%s', '') ORDER BY language DESC", $path, $path_language));
-      $map[$path_language][$path] = $alias;
-      return $alias;
+      $result = db_query("SELECT dst, language FROM {url_alias} WHERE src = '%s'", $path);
+      while ($alias = db_fetch_object($result)) {
+        if (isset($alias->language) && $alias->language == $path_language || empty($map[$path_language][$path]) && strpos($path, 'node/')) {
+          $dst = $map[$path_language][$path] = $alias->dst;
+        }
+      }      
+      return $dst;
     }
     // Check $no_src for this $path in case we've already determined that there
     // isn't a path that has this alias
@@ -76,10 +81,13 @@ function drupal_lookup_path($action, $pa
       $src = '';
       if (!isset($map[$path_language]) || !($src = array_search($path, $map[$path_language]))) {
         // Get the most fitting result falling back with alias without language
-        if ($src = db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s' AND language IN('%s', '') ORDER BY language DESC", $path, $path_language))) {
-          $map[$path_language][$src] = $path;
-        }
-        else {
+        $result = db_query("SELECT src, language FROM {url_alias} WHERE dst = '%s'", $path);
+        while ($alias = db_fetch_object($result)) {
+          if (isset($alias->language) && $alias->language == $path_language || empty($map[$path_language][$path])) {
+            $src = $map[$path_language][$src] = $alias->src;
+          }
+        } 
+        if (empty($src)) {
           // We can't record anything into $map because we do not have a valid
           // index and there is no need because we have not learned anything
           // about any Drupal path. Thus cache to $no_src.
