Fix #5044; add unit tests for img() HTML helper
diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php
index de1b92c..87a5f9b 100644
--- a/system/helpers/html_helper.php
+++ b/system/helpers/html_helper.php
@@ -192,7 +192,7 @@
foreach ($src as $k => $v)
{
- if ($k === 'src' && ! preg_match('#^([a-z]+:)?//#i', $v))
+ if ($k === 'src' && ! preg_match('#^(data:[a-z,;])|(([a-z]+:)?(?<!data:)//)#i', $v))
{
if ($index_page === TRUE)
{
diff --git a/tests/codeigniter/helpers/html_helper_test.php b/tests/codeigniter/helpers/html_helper_test.php
index d66ad89..3cf1016 100644
--- a/tests/codeigniter/helpers/html_helper_test.php
+++ b/tests/codeigniter/helpers/html_helper_test.php
@@ -40,6 +40,20 @@
// ------------------------------------------------------------------------
+ public function test_img()
+ {
+ $this->ci_set_config('base_url', 'http://localhost/');
+ $this->assertEquals('<img src="http://localhost/test" alt="" />', img("test"));
+ $this->assertEquals('<img src="data:foo/bar,baz" alt="" />', img("data:foo/bar,baz"));
+ $this->assertEquals('<img src="http://localhost/data://foo" alt="" />', img("data://foo"));
+ $this->assertEquals('<img src="//foo.bar/baz" alt="" />', img("//foo.bar/baz"));
+ $this->assertEquals('<img src="http://foo.bar/baz" alt="" />', img("http://foo.bar/baz"));
+ $this->assertEquals('<img src="https://foo.bar/baz" alt="" />', img("https://foo.bar/baz"));
+ $this->assertEquals('<img src="ftp://foo.bar/baz" alt="" />', img("ftp://foo.bar/baz"));
+ }
+
+ // ------------------------------------------------------------------------
+
public function test_Ul()
{
$expect = <<<EOH
@@ -89,4 +103,4 @@
}
-}
\ No newline at end of file
+}
diff --git a/tests/mocks/ci_testconfig.php b/tests/mocks/ci_testconfig.php
index f80adc5..afdb710 100644
--- a/tests/mocks/ci_testconfig.php
+++ b/tests/mocks/ci_testconfig.php
@@ -1,20 +1,20 @@
<?php
-class CI_TestConfig {
+class CI_TestConfig extends CI_Config {
public $config = array();
public $_config_paths = array(APPPATH);
public $loaded = array();
- public function item($key)
+ public function item($key, $index = '')
{
return isset($this->config[$key]) ? $this->config[$key] : FALSE;
}
- public function load($file, $arg2 = FALSE, $arg3 = FALSE)
+ public function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
{
$this->loaded[] = $file;
return TRUE;
}
-}
\ No newline at end of file
+}
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 8283f53..8d2beb7 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -34,6 +34,7 @@
- Fixed a bug (#5006) - :doc:`common function <general/common_functions>` :php:func:`get_mimes()` didn't load *application/config/mimes.php* if an environment specific config exists.
- Fixed a bug (#5006) - :doc:`common function <general/common_functions>` :php:func:`remove_invisible_characters()` didn't remove URL-encoded ``0x7F``.
- Fixed a bug (#4815) - :doc:`Database Library <database/index>` stripped URL-encoded sequences while escaping strings with the 'mssql' driver.
+- Fixed a bug (#5044) - :doc:`HTML Helper <helpers/html_helper>` function :php:func:`img()` didn't accept ``data:`` URI schemes for the image source.
Version 3.1.3
=============