Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stripslashes to mssql result columns #13534

Merged
merged 1 commit into from
Jan 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 46 additions & 36 deletions libraries/joomla/database/driver/sqlsrv.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,39 +543,6 @@ public function insertid()
return (int) $this->loadResult();
}

/**
* Method to get the first field of the first row of the result set from the database query.
*
* @return mixed The return value or null if the query failed.
*
* @since 12.1
* @throws RuntimeException
*/
public function loadResult()
{
$ret = null;

// Execute the query and get the result set cursor.
if (!($cursor = $this->execute()))
{
return;
}

// Get the first row from the result set as an array.
if ($row = sqlsrv_fetch_array($cursor, SQLSRV_FETCH_NUMERIC))
{
$ret = $row[0];
}

// Free up system resources and return.
$this->freeResult($cursor);

// For SQLServer - we need to strip slashes
$ret = stripslashes($ret);

return $ret;
}

/**
* Execute the SQL statement.
*
Expand Down Expand Up @@ -942,7 +909,21 @@ public function transactionStart($asSavepoint = false)
*/
protected function fetchArray($cursor = null)
{
return sqlsrv_fetch_array($cursor ? $cursor : $this->cursor, SQLSRV_FETCH_NUMERIC);
$row = sqlsrv_fetch_array($cursor ? $cursor : $this->cursor, SQLSRV_FETCH_NUMERIC);

if (is_array($row))
{
// For SQLServer - we need to strip slashes
foreach ($row as &$value)
{
if ($value !== null)
{
$value = stripslashes($value);
}
}
}

return $row;
}

/**
Expand All @@ -956,7 +937,21 @@ protected function fetchArray($cursor = null)
*/
protected function fetchAssoc($cursor = null)
{
return sqlsrv_fetch_array($cursor ? $cursor : $this->cursor, SQLSRV_FETCH_ASSOC);
$row = sqlsrv_fetch_array($cursor ? $cursor : $this->cursor, SQLSRV_FETCH_ASSOC);

if (is_array($row))
{
// For SQLServer - we need to strip slashes
foreach ($row as &$value)
{
if ($value !== null)
{
$value = stripslashes($value);
}
}
}

return $row;
}

/**
Expand All @@ -971,7 +966,22 @@ protected function fetchAssoc($cursor = null)
*/
protected function fetchObject($cursor = null, $class = 'stdClass')
{
return sqlsrv_fetch_object($cursor ? $cursor : $this->cursor, $class);
$row = sqlsrv_fetch_object($cursor ? $cursor : $this->cursor, $class);

if (is_object($row))
{
// For SQLServer - we need to strip slashes
foreach (get_object_vars($row) as $key => $value)
{
// Check public variable from object including those from $class, ex. JMenuItem
if (is_string($value))
{
$row->$key = stripslashes($value);
}
}
}

return $row;
}

/**
Expand Down
17 changes: 16 additions & 1 deletion libraries/joomla/database/iterator/sqlsrv.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,22 @@ public function count()
*/
protected function fetchObject()
{
return sqlsrv_fetch_object($this->cursor, $this->class);
$row = sqlsrv_fetch_object($this->cursor, $this->class);

if (is_object($row))
{
// For SQLServer - we need to strip slashes
foreach (get_object_vars($row) as $key => $value)
{
// Check public variable from object including those from $class, ex. JMenuItem
if (is_string($value))
{
$row->$key = stripslashes($value);
}
}
}

return $row;
}

/**
Expand Down