summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2017-10-13 16:04:35 +0200
committerAndrey Andreev <narf@devilix.net>2017-10-13 16:04:35 +0200
commitfa2a0c58eb0f6421e3819df8a8873b5a5e4ebb58 (patch)
tree2f14da1862f0f4a30796f5c8d72b3caf1669f776 /system
parentc54fd9116d49714390aa109cead0545c80ebb057 (diff)
Fix #5297
Diffstat (limited to 'system')
-rw-r--r--system/database/DB_driver.php12
1 files changed, 8 insertions, 4 deletions
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index 0b13a2f82..c18701db3 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -1926,15 +1926,19 @@ abstract class CI_DB_driver {
$i++;
}
+ // dbprefix may've already been applied, with or without the identifier escaped
+ $ec = '(?<ec>'.preg_quote(is_array($this->_escape_char) ? $this->_escape_char[0] : $this->_escape_char).')?';
+ isset($ec[0]) && $ec .= '?'; // Just in case someone has disabled escaping by forcing an empty escape character
+
// Verify table prefix and replace if necessary
- if ($this->swap_pre !== '' && strpos($parts[$i], $this->swap_pre) === 0)
+ if ($this->swap_pre !== '' && preg_match('#^'.$ec.preg_quote($this->swap_pre).'#', $parts[$i]))
{
- $parts[$i] = preg_replace('/^'.$this->swap_pre.'(\S+?)/', $this->dbprefix.'\\1', $parts[$i]);
+ $parts[$i] = preg_replace('#^'.$ec.preg_quote($this->swap_pre).'(\S+?)#', '\\1'.$this->dbprefix.'\\2', $parts[$i]);
}
// We only add the table prefix if it does not already exist
- elseif (strpos($parts[$i], $this->dbprefix) !== 0)
+ else
{
- $parts[$i] = $this->dbprefix.$parts[$i];
+ preg_match('#^'.$ec.preg_quote($this->dbprefix).'#', $parts[$i]) OR $parts[$i] = $this->dbprefix.$parts[$i];
}
// Put the parts back together