diff --git a/pathologic.module b/pathologic.module
index bfa016b..b7e2e13 100755
--- a/pathologic.module
+++ b/pathologic.module
@@ -223,7 +223,7 @@ function _pathologic_replace($matches) {
       'query' => $parts['qparts'],
       'fragment' => isset($parts['fragment']) ? $parts['fragment'] : NULL,
       'absolute' => $settings['current_settings']['absolute'],
-      'language' => isset($langs[$settings['langcode']]) ? $langs[$settings['langcode']] : NULL,
+      'language' => (object) array('language' => 'und'),
     )
   );
   // $matches[1] will be the tag attribute; src, href, etc.
diff --git a/pathologic.test b/pathologic.test
index 7318d21..156209d 100644
--- a/pathologic.test
+++ b/pathologic.test
@@ -141,3 +141,76 @@ class PathologicTestCase extends DrupalWebTestCase {
     );
   }
 }
+
+class PathologicTestLanguageCase extends DrupalWebTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => 'Pathologic path filtering language handling',
+      'description' => 'Test Pathologic&rsquo;s path translation and conversion with language prefix.',
+      'group' => 'Filter',
+    );
+  }
+
+  function setUp() {
+    parent::setUp('locale', 'locale_test', 'pathologic');
+
+    // Create and login user.
+    $admin_user = $this->drupalCreateUser(array('administer languages', 'administer content types', 'administer url aliases', 'access administration pages', 'create page content', 'edit any page content'));
+    $this->drupalLogin($admin_user);
+
+    // Add language.
+    $edit = array('langcode' => 'fr');
+    $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
+
+    // Set "Basic page" content type to use multilingual support.
+    $this->drupalGet('admin/structure/types/manage/page');
+    $edit = array('language_content_type' => 1);
+    $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
+
+    // Enable URL language detection and selection.
+    $edit = array('language[enabled][locale-url]' => 1);
+    $this->drupalPost('admin/config/regional/language/configure', $edit, t('Save settings'));
+
+    // Change user language preference.
+    $edit = array('language' => 'fr');
+    $this->drupalPost("user/{$admin_user->uid}/edit", $edit, t('Save'));
+  }
+
+  function testPathologicLanguage() {
+    // Build a phony filter
+    $filter = new stdClass;
+    $filter->callback = '_pathologic';
+    $filter->settings = array(
+      'absolute' => TRUE,
+      'local_paths' => "http://example.com/qux/abc",
+    );
+    $filter->format = 0;
+
+    // Create a node.
+    $title_value = $this->randomName(8);
+    $custom_path = $this->randomName(8) . "/oranges";
+    $edit = array();
+    $edit['title'] = $title_value;
+    $edit['language'] = 'fr';
+    $edit['path[alias]'] = $custom_path;
+    $this->drupalPost('node/add/page', $edit, t('Save'));
+    $node = $this->drupalGetNodeByTitle($edit['title']);
+
+    // Clear the path lookup cache.
+    drupal_lookup_path('wipe');
+    drupal_static_reset('language_list');
+    drupal_static_reset('locale_url_outbound_alter');
+
+    // Get the language object
+    $languages = language_list();
+    $lang = $languages['fr'];
+
+    // Test with path language prefix
+    $this->assertEqual(
+      _pathologic_filter('<a href="http://example.com/qux/abc/fr/' . $custom_path . '"></a>', $filter, NULL, 'fr', NULL, NULL),
+      '<a href="' . url('node/' . $node->nid, array('absolute' => TRUE, 'language' => $lang)) . '"></a>',
+      t('URLs with language prefix')
+    );
+    $this->drupalLogout();
+  }
+}
