Skip to content
This repository has been archived by the owner on Nov 26, 2017. It is now read-only.

Validate that the key parameter is a string #1486

Merged
merged 1 commit into from Aug 23, 2012
Merged

Validate that the key parameter is a string #1486

merged 1 commit into from Aug 23, 2012

Conversation

pasamio
Copy link
Contributor

@pasamio pasamio commented Aug 23, 2012

This pull request validates that the $key parameter provided to the function is actually a string before trying to use this. I came across this as I was working to modify JTable to be able to support multiple primary keys in a somewhat transparent way. By default JTable passes through it's keys onto the database insertObject and updateObject function which works well for single keys but not properly for insertObject when the $key is an array.

This pull request validates that the `$key` parameter provided to the function is actually a string before trying to use this. I came across this as I was working to modify JTable to be able to support multiple primary keys in a somewhat transparent way. By default JTable passes through it's keys onto the database `insertObject` and `updateObject` function which works well for single keys but not properly for `insertObject` when the `$key` is an array.
LouisLandry added a commit that referenced this pull request Aug 23, 2012
Validate that the key parameter is a string
@LouisLandry LouisLandry merged commit c13cc86 into joomla:staging Aug 23, 2012
@@ -851,7 +851,7 @@ public function insertObject($table, &$object, $key = null)

// Update the primary key if it exists.
$id = $this->insertid();
if ($key && $id)
if ($key && $id && is_string($key))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it would be enough to do if (is_string($key) && $id). If the condition fails for $key it will fail for is_string($key) too.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if $key would not exist you would then get a Notice: Undefined variable: key
That's why $key is tested first and cannot be left.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but $key is by default null. I can't see any case when $key is not defined in this context.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right (I was wrong).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants