Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

To avoid Fatal error with JEditor::getButtons (for issue #660) #1093

Closed
wants to merge 11 commits into from

6 participants

@Buddhima

File: joomla-platform / libraries / joomla / html / editor.php
Method: getButtons()

Issue: If the $className would not exists (due to plugin class is missing) , assigning to $temp variable becomes unsafe

Solution: Put the assiging inside a try catch block, so that not existance of plugin class would not disturb the flow of foreach loop

Signed-off-by: Buddhima Wijeweera

@Buddhima Buddhima for issue #660
To avoid unsafe operation

Signed-off-by: Buddhima Wijeweera <buddhimawijeweera@yahoo.com>
532ca47
@mbabker
Owner

You need to fix your code style first - http://developer.joomla.org/pulls/pulls/1093.html

Also, instead of echoing the message, you should be returning an error. Instead of the try/catch method you've proposed, maybe the current if statement would work fine, but add an else so that an Exception is thrown and the caller can handle the error.

libraries/joomla/html/editor.php
((5 lines not shown))
// Try to authenticate
- if ($temp = $plugin->onDisplay($editor, $this->asset, $this->author))
- {
- $result[] = $temp;
- }
+ // Unsafe opearation, might cause an exception if $className not exists
@elinw
elinw added a note

operation

@Buddhima
Buddhima added a note

:D a mistake. Thanks for pointing out
Corrected !!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Buddhima added some commits
@Buddhima Buddhima commit 2 after applying coding standards. Thanks mbabker!
Signed-off-by: Buddhima Wijeweera <buddhimawijeweera@yahoo.com>
af7d4c3
@Buddhima Buddhima corrected "operation" spellings
Signed-off-by: Buddhima Wijeweera <buddhimawijeweera@yahoo.com>
deb68e1
@Buddhima Buddhima Throwing Exception instead of try-catch block
Signed-off-by: Buddhima Wijeweera <buddhimawijeweera@yahoo.com>
a89332b
@Buddhima Buddhima changed Exception to InvalidArgumentException, added @throws in docblock
Signed-off-by: Buddhima Wijeweera <buddhimawijeweera@yahoo.com>
0bd1796
@Buddhima Buddhima used single quotes and tabs instead of spaces
Signed-off-by: Buddhima Wijeweera <buddhimawijeweera@yahoo.com>
74b3027
@Buddhima Buddhima changed quotes and added tabs
Signed-off-by: Buddhima Wijeweera <buddhimawijeweera@yahoo.com>
b66f8c6
@Buddhima Buddhima removed spaces and replaced with tabs in latter section
Signed-off-by: Buddhima Wijeweera <buddhimawijeweera@yahoo.com>
24ed611
@Buddhima Buddhima Corrected error in
libraries/joomla/html/editor.php:470

Signed-off-by: Buddhima Wijeweera <buddhimawijeweera@yahoo.com>
434f00e
libraries/joomla/html/editor.php
@@ -426,6 +426,8 @@ public function setContent($editor, $html)
*
* @return array
*
+ * @throws InvalidArgumentException If plugin required does not exists
+ *
@chdemko
chdemko added a note

Please indent correctly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
libraries/joomla/html/editor.php
((8 lines not shown))
// Try to authenticate
if ($temp = $plugin->onDisplay($editor, $this->asset, $this->author))
{
$result[] = $temp;
}
+
@chdemko
chdemko added a note

superfluous line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Buddhima added some commits
@Buddhima Buddhima Indent settled correctly and remove superfluous line
Signed-off-by: Buddhima Wijeweera <buddhimawijeweera@yahoo.com>
dc37ef8
@Buddhima Buddhima Indent settled correctly
Signed-off-by: Buddhima Wijeweera <buddhimawijeweera@yahoo.com>
dfc11f3
@chdemko

The pull request cannot be merged

@Buddhima

Hi, can you tell me why it is failing?

@chdemko

you have to merge with the current trunk

@elinw

The issue is not that the pull request can't be merged (that would be shown on the pull tester report with red) All of the pull requests with ?? in them have the same failure. I'm not sure if it is because they all have a dependency on JHtml or not, but that is possible. Those test reports were generated on May 5 and have not been updated since.
All of them show this as the failing line
https://github.com/joomla/joomla-platform/blob/staging/tests/suites/unit/joomla/html/JHtmlTest.php#L896

@Buddhima

Thanks Elin for pointing to the correct place :)

@elinw

Okay now you need to update your branch, since the pulltester has rerun and it says it is not able to merge cleanly.

@realityking
Collaborator

This still doesn't merge cleanly. Also I'm wondering under what circumstances this would be triggered.

@elinw

@realityking if the plugin is missing but you put the button in the field definition, I believe.

@Buddhima will you please rebase this or close it until you get it rebased?

@LouisLandry

@Buddhima the library in question has been removed from the platform and added to the CMS tree. I'd suggest you submitting this to the CMS repository since it is a very smart and correct change in behavior. I'm closing this since it is no longer relevant for the platform. Apologies for not getting to it sooner.

@LouisLandry LouisLandry closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 1, 2012
  1. @Buddhima

    for issue #660

    Buddhima authored
    To avoid unsafe operation
    
    Signed-off-by: Buddhima Wijeweera <buddhimawijeweera@yahoo.com>
  2. @Buddhima

    commit 2 after applying coding standards. Thanks mbabker!

    Buddhima authored
    Signed-off-by: Buddhima Wijeweera <buddhimawijeweera@yahoo.com>
  3. @Buddhima

    corrected "operation" spellings

    Buddhima authored
    Signed-off-by: Buddhima Wijeweera <buddhimawijeweera@yahoo.com>
  4. @Buddhima

    Throwing Exception instead of try-catch block

    Buddhima authored
    Signed-off-by: Buddhima Wijeweera <buddhimawijeweera@yahoo.com>
  5. @Buddhima

    changed Exception to InvalidArgumentException, added @throws in docblock

    Buddhima authored
    Signed-off-by: Buddhima Wijeweera <buddhimawijeweera@yahoo.com>
  6. @Buddhima

    used single quotes and tabs instead of spaces

    Buddhima authored
    Signed-off-by: Buddhima Wijeweera <buddhimawijeweera@yahoo.com>
  7. @Buddhima

    changed quotes and added tabs

    Buddhima authored
    Signed-off-by: Buddhima Wijeweera <buddhimawijeweera@yahoo.com>
  8. @Buddhima

    removed spaces and replaced with tabs in latter section

    Buddhima authored
    Signed-off-by: Buddhima Wijeweera <buddhimawijeweera@yahoo.com>
Commits on Apr 6, 2012
  1. @Buddhima

    Corrected error in

    Buddhima authored
    libraries/joomla/html/editor.php:470
    
    Signed-off-by: Buddhima Wijeweera <buddhimawijeweera@yahoo.com>
Commits on Apr 14, 2012
  1. @Buddhima

    Indent settled correctly and remove superfluous line

    Buddhima authored
    Signed-off-by: Buddhima Wijeweera <buddhimawijeweera@yahoo.com>
  2. @Buddhima

    Indent settled correctly

    Buddhima authored
    Signed-off-by: Buddhima Wijeweera <buddhimawijeweera@yahoo.com>
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 0 deletions.
  1. +6 −0 libraries/joomla/html/editor.php
View
6 libraries/joomla/html/editor.php
@@ -426,6 +426,8 @@ public function setContent($editor, $html)
*
* @return array
*
+ * @throws InvalidArgumentException If plugin required does not exists
+ *
* @since 11.1
*/
public function getButtons($editor, $buttons = true)
@@ -454,6 +456,10 @@ public function getButtons($editor, $buttons = true)
{
$plugin = new $className($this, (array) $plugin);
}
+ else
+ {
+ throw new InvalidArgumentException('Class does not exists: ' . $className);
+ }
// Try to authenticate
if ($temp = $plugin->onDisplay($editor, $this->asset, $this->author))
Something went wrong with that request. Please try again.