Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Validation does not exist: regex.

2»

Comments

  • Options

    I am getting a "The client id must contain only letters, numbers and dashes." or a "Bonk" when changing line 475 or commenting out the line altogether, respectively, and trying to save a connection.

    From what I can tell:

    1) jsConnect 1.4.1 has a problem beyond this validation attempt.

    2) Looks like the problem is not only the ValidateRule call in class.jsconnect.plugin.php, but in the Gdn_Validation class:

         public static function ValidateRule($Value, $FieldName, $Rule, $CustomError = FALSE) {
              // Figure out the type of rule.
              if (is_string($Rule)) {
                 if (StringBeginsWith($Rule, 'regex:', TRUE)) {
                    $RuleName = 'regex';
                    $Args = substr($Rule, 6);
                 } elseif (StringBeginsWith($Rule, 'function:', TRUE)) {
                    $RuleName = substr($Rule, 9);
                 } else {
                    $RuleName = $Rule;
                 }
              } elseif (is_array($Rule)) {
                 $RuleName = GetValue('Name', $Rule);
                 $Args = GetValue('Args', $Rule);
              }
    
              if (!isset($Args))
                 $Args = NULL;
    
              if (function_exists($RuleName)) {
                 $Result = $RuleName($Value, $Args);
                 if ($Result === TRUE)
                    return TRUE;
                 elseif ($CustomError)
                    return $CustomError;
                 elseif (is_string($Result))
                    return $Result;
                 else
                    return sprintf(T($RuleName), T($FieldName));
              } else {
                 return sprintf('Validation does not exist: %s.', $RuleName);
              }
           }
    

    Which theoretically, should parse the 'regex: ... ' rule correctly, but then it fails when checking for a function with the name "regex".

                        $RuleName = 'regex';
    

    Should be assigned as:

                        $RuleName = 'ValidateRegex';
    

    3) "ValidateRegex" exists indeed as validation function:

       function ValidateRegex($Value, $Regex) {
          preg_match($Regex, $Value, $Matches);
          return is_array($Matches) && count($Matches) > 0 ? TRUE : FALSE;
       }
    

    However it uses preg_match which expects a specific regex syntax '/.../i' and therefore the regex given in either version of the ValidateRule call would need to be '/^[a-z0-9_-]+$/i'.

  • Options

    Tried:

    $Form->ValidateRule('AuthenticationKey', array('Name'=>'ValidateRegex', 'Args' => '/^[a-z0-9_-]+$/i'), T('The client id must contain only letters, numbers and dashes.')); 
    

    which now seems to pass form validation, but now ends up back at the "Bonk" when trying to save the jsConnect connection. Is there any way to get a meaningful error message instead of "Bonk"?

  • Options
    peregrineperegrine MVP
    edited January 2014

    yes see the Bonk on the wiki or look on the docs page for link to errors. The info is all there.

    http://vanillaforums.org/docs/errors

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options

    @HaD read this post

    http://vanillaforums.org/discussion/comment/201182/#Comment_201182

    Yes it true that that code, isn't functional however passing an arbitrary callback function is handled elsewhere in the code.

    ....
    } elseif (is_array($Rule)) {
    $RuleName = GetValue('Name', $Rule);
    $Args = GetValue('Args', $Rule);
    }
    

    However it uses preg_match which expects a specific regex syntax '/.../i' and therefore the regex given in either version of the ValidateRule call would need to be '/^[a-z0-9_-]+$/i'.

    This isn't actually true.

    http://uk1.php.net/manual/en/regexp.reference.delimiters.php said:
    When using the PCRE functions, it is required that the pattern is enclosed by delimiters. A delimiter can be any non-alphanumeric, non-backslash, non-whitespace character.

    It is actually quite a good idea to avoid / becuase it is common character, and therefore you don't need to escape it. using backtick is good becuase is less used.

    grep is your friend.

  • Options

    @x00:

    About callback: While you can pass an arbitrary callback function to the validation, it fails at the point of

    ...
    if (function_exists($RuleName)) { 
    ...
    

    It does fail for "regex", but not for "ValidateRegex".

    About delimiters: Indeed, you could use any delimiter. The original code suggests ``` as delimiter. I've tried:

    $Form->ValidateRule('AuthenticationKey', array('Name'=>'ValidateRegex', 'Args' => '^[a-z0-9_-]+$`i'), T('The client id must contain only letters, numbers and dashes.'));
    

    and (note the added delimiter at the beginning of the reg ex):

    $Form->ValidateRule('AuthenticationKey', array('Name'=>'ValidateRegex', 'Args' => '`^[a-z0-9_-]+$`i'), T('The client id must contain only letters, numbers and dashes.'));
    

    Only using / as delimiter delivered a correct validation result though:

    $Form->ValidateRule('AuthenticationKey', array('Name'=>'ValidateRegex', 'Args' => '/^[a-z0-9_-]+$/i'), T('The client id must contain only letters, numbers and dashes.'));
    
  • Options

    @HaD said:
    x00:

    About callback: While you can pass an arbitrary callback function to the validation, it fails at the point of

    ...
    if (function_exists($RuleName)) {
    ...

    It does fail for "regex", but not for "ValidateRegex".

    Ah but if you pass an array, it skips the bit of code with $RuleName = 'regex';

     } elseif (is_array($Rule)) {
    $RuleName = GetValue('Name', $Rule);
    $Args = GetValue('Args', $Rule);
    }
    

    it accepts whatever function in the Name parameter. if you think about it wouldn't make sense to pass a callback then overrule that with some hard coded callback.

    Btw the second example really should work, you would have to debug to why it is not. The first one is not valid.

    grep is your friend.

  • Options

    @x00: You are correct about passing an array. However, if you do not pass an array, and the rule string is prefixed with regex: then the $RuleName is set to 'regex' and the $Args are the remainder of the rule string. This is in Gn_Validation::ValidateRule, Line 5 & 6 in the code I've copied earlier.

    Line 5 in this (Garden) function should be corrected to read:

    $RuleName = 'ValidateRegex';
    

    so that the function existance check in Gn_Validation::ValidateRule, Line 20, does not fail.

  • Options
    HaDHaD New
    edited January 2014

    I've achieved a successful validation, but the database insert statement fails:

    Unknown column 'IsDefault' in 'field list'
    insert ignore GDN_UserAuthenticationProvider 
    (Name, AuthenticationKey, URL, AssociationSecret, AuthenticateUrl, SignInUrl, RegisterUrl, SignOutUrl, IsDefault, AuthenticationSchemeAlias, AssociationHashMethod, Attributes) 
    values (:Name, :AuthenticationKey, :URL, :AssociationSecret, :AuthenticateUrl, :SignInUrl, :RegisterUrl, :SignOutUrl, :IsDefault, :AuthenticationSchemeAlias, :AssociationHashMethod, :Attributes)
    

    Could this be a remnant of jsConnect 1.0.3 not uninstalled completely on the database level, and jsConnect 1.4.1 not updating the tables?

    If so, what would be the correct way of cleaning up and reinstalling jsConnect 1.4.1?

    Here's the backtrace:

    /mentorship/library/database/class.database.phpPHP::Gdn_ErrorHandler();
    [/mentorship/library/database/class.database.php:280] PHP::trigger_error();
    [/mentorship/library/database/class.sqldriver.php:1657] Gdn_Database->Query();
    [/mentorship/library/database/class.sqldriver.php:1128] Gdn_SQLDriver->Query();
    [/mentorship/plugins/jsconnect/class.jsconnect.plugin.php:492] Gdn_SQLDriver->Insert();
    [/mentorship/plugins/jsconnect/class.jsconnect.plugin.php:443] JsConnectPlugin->Settings_AddEdit();
    [/mentorship/library/core/class.pluginmanager.php:713] JsConnectPlugin->SettingsController_JsConnect_Create();
    [/mentorship/library/core/class.dispatcher.php:313] Gdn_PluginManager->CallNewMethod();
    [/mentorship/index.php:53] Gdn_Dispatcher->Dispatch();
    
  • Options

    If so, what would be the correct way of cleaning up and reinstalling jsConnect 1.4.1?

    try disabling and enabling.

    grep is your friend.

  • Options

    @HaD said:
    x00: You are correct about passing an array. However, if you do not pass an array, and the rule string is prefixed with regex: then the $RuleName is set to 'regex' and the $Args are the remainder of the rule string. This is in Gn_Validation::ValidateRule, Line 5 & 6 in the code I've copied earlier.

    Line 5 in this (Garden) function should be corrected to read:

    $RuleName = 'ValidateRegex';

    so that the function existance check in Gn_Validation::ValidateRule, Line 20, does not fail.

    sure I'm aware of that, that is what I identified earlier.

    grep is your friend.

  • Options

    Been there with disabling and enabling. How about?

    1. Disabling & deleting.
    2. Deleting files, if any.
    3. Deleting tables, if any.
    4. Reinstalling a clean copy.
    5. Hoping it works.

    :)

  • Options
    hgtonighthgtonight ∞ · New Moderator

    Not all plugins check the structure every time the plugin is enabled.

    Go to http://forum.example.com/utility/structure to run the structure update for all enabled applications and plugins.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options
    HaDHaD New
    edited February 2014

    After disabling / removing / enabling the jsConnect plugin and also deleting the table manually (it did get rebuilt without the IsDefault column again), I've just added the column manually to the table GDN_UserAuthenticationProvider and I was able to save the connection settings.

  • Options
    edited March 2014

    To fix this I commented out Line 475 in class.jsconnect.plugin.php and then I ran this SQL on the database:

    ALTER TABLEGDN_UserAuthenticationProviderADDIsDefaultBOOLEAN NOT NULL DEFAULT FALSE ;

    Hope it helps someone

Sign In or Register to comment.