diff --git a/includes/common.inc b/includes/common.inc
index 6f85b52..d0ce1b6 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -2436,12 +2436,26 @@ function l($text, $path, array $options = array()) {
   // Merge in defaults.
   $options += array(
     'attributes' => array(),
+    'query' => array(),
     'html' => FALSE,
   );
 
   // Append active class.
-  if (($path == $_GET['q'] || ($path == '<front>' && drupal_is_front_page())) &&
-      (empty($options['language']) || $options['language']->language == $language_url->language)) {
+  // The link is only active, if its path corresponds to the current path, the
+  // language of the linked path is equal to the current language, and if the
+  // query parameters of the link equal those of the current request, since the
+  // same request with different query parameters may yield a different page
+  // (e.g., pagers).
+  $is_active = ($path == current_path() || ($path == '<front>' && drupal_is_front_page()));
+  $is_active = $is_active && (empty($options['language']) || $options['language']->language == $language_url->language);
+  if ($is_active) {
+    // The query parameters of the current request are in $_GET, but the 'q'
+    // parameter in there should be ignored, as that is the Drupal path.
+    $real_query_params = $_GET;
+    unset($real_query_params['q']);
+    $is_active = $real_query_params == $options['query'];
+  }
+  if ($is_active) {
     $options['attributes']['class'][] = 'active';
   }
 
diff --git a/includes/pager.inc b/includes/pager.inc
index c060d0e..94e01d6 100644
--- a/includes/pager.inc
+++ b/includes/pager.inc
@@ -630,13 +630,7 @@ function theme_pager_link($variables) {
     }
   }
 
-  // @todo l() cannot be used here, since it adds an 'active' class based on the
-  //   path only (which is always the current path for pager links). Apparently,
-  //   none of the pager links is active at any time - but it should still be
-  //   possible to use l() here.
-  // @see http://drupal.org/node/1410574
-  $attributes['href'] = url($_GET['q'], array('query' => $query));
-  return '<a' . drupal_attributes($attributes) . '>' . check_plain($text) . '</a>';
+  return l($text, current_path(), array('query' => $query, 'attributes' => $attributes));
 }
 
 /**
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test
index 8694ff3..86b1ef4 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -74,6 +74,10 @@ class DrupalAlterTestCase extends DrupalWebTestCase {
  * inheriting from a web test case rather than a unit test case.
  */
 class CommonURLUnitTest extends DrupalWebTestCase {
+  protected function setUp() {
+    parent::setUp(array('common_test'));
+  }
+
   public static function getInfo() {
     return array(
       'name' => 'URL generation tests',
@@ -97,8 +101,24 @@ class CommonURLUnitTest extends DrupalWebTestCase {
    * Tests for active class in l() function.
    */
   function testLActiveClass() {
-    $link = l($this->randomName(), $_GET['q']);
-    $this->assertTrue($this->hasClass($link, 'active'), format_string('Class @class is present on link to the current page', array('@class' => 'active')));
+    $path = 'common-test/l-active-class';
+    $options = array();
+
+    $this->drupalGet($path, $options);
+    $links = $this->xpath('//a[@href = :href and contains(@class, :class)]', array(':href' => url($path, $options), ':class' => 'active'));
+    $this->assertTrue(isset($links[0]), 'A link to the current page is marked active.');
+
+    $options = array('query' => array('foo' => 'bar'));
+    $links = $this->xpath('//a[@href = :href and not(contains(@class, :class))]', array(':href' => url($path, $options), ':class' => 'active'));
+    $this->assertTrue(isset($links[0]), 'A link to the current page with a query string when the current page has no query string is not marked active.');
+
+    $this->drupalGet($path, $options);
+    $links = $this->xpath('//a[@href = :href and contains(@class, :class)]', array(':href' => url($path, $options), ':class' => 'active'));
+    $this->assertTrue(isset($links[0]), 'A link to the current page with a query string that matches the current query string is marked active.');
+
+    $options = array();
+    $links = $this->xpath('//a[@href = :href and not(contains(@class, :class))]', array(':href' => url($path, $options), ':class' => 'active'));
+    $this->assertTrue(isset($links[0]), 'A link to the current page without a query string when the current page has a query string is not marked active.');
   }
 
   /**
@@ -108,7 +128,6 @@ class CommonURLUnitTest extends DrupalWebTestCase {
     $class = $this->randomName();
     $link = l($this->randomName(), $_GET['q'], array('attributes' => array('class' => array($class))));
     $this->assertTrue($this->hasClass($link, $class), format_string('Custom class @class is present on link when requested', array('@class' => $class)));
-    $this->assertTrue($this->hasClass($link, 'active'), format_string('Class @class is present on link to the current page', array('@class' => 'active')));
   }
 
   private function hasClass($link, $class) {
diff --git a/modules/simpletest/tests/common_test.module b/modules/simpletest/tests/common_test.module
index 674a494..35c6e45 100644
--- a/modules/simpletest/tests/common_test.module
+++ b/modules/simpletest/tests/common_test.module
@@ -52,6 +52,12 @@ function common_test_menu() {
     'access arguments' => array('access content'),
     'type' => MENU_CALLBACK,
   );
+  $items['common-test/l-active-class'] = array(
+    'title' => 'Test l() adding of active class',
+    'page callback' => 'common_test_l_active_class',
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+  );
   return $items;
 }
 
@@ -263,6 +269,29 @@ function common_test_js_and_css_querystring() {
 }
 
 /**
+ * Page callback: Displays links to the current page, one with a query string.
+ */
+function common_test_l_active_class() {
+  return array(
+    'no_query' => array(
+      '#type' => 'link',
+      '#title' => t('Link with no query string'),
+      '#href' => current_path(),
+    ),
+    'with_query' => array(
+      '#type' => 'link',
+      '#title' => t('Link with a query string'),
+      '#href' => current_path(),
+      '#options' => array(
+        'query' => array(
+          'foo' => 'bar',
+        ),
+      ),
+    ),
+  );
+}
+
+/**
  * Implements hook_cron().
  *
  * System module should handle if a module does not catch an exception and keep
