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:
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'.
$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"?
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'.
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.
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.'));
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.
@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.
@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.
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.
Comments
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:
Which theoretically, should parse the 'regex: ... ' rule correctly, but then it fails when checking for a function with the name "regex".
Should be assigned as:
3) "ValidateRegex" exists indeed as validation function:
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'.
Tried:
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"?
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.
@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.
This isn't actually true.
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.
@x00:
About callback: While you can pass an arbitrary callback function to the validation, it fails at the point of
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:
and (note the added delimiter at the beginning of the reg ex):
Only using
/
as delimiter delivered a correct validation result though:Ah but if you pass an array, it skips the bit of code with
$RuleName = 'regex';
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.
@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:
so that the function existance check in Gn_Validation::ValidateRule, Line 20, does not fail.
I've achieved a successful validation, but the database insert statement fails:
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:
try disabling and enabling.
grep is your friend.
sure I'm aware of that, that is what I identified earlier.
grep is your friend.
Been there with disabling and enabling. How about?
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.
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.To fix this I commented out Line 475 in class.jsconnect.plugin.php and then I ran this SQL on the database:
ALTER TABLE
GDN_UserAuthenticationProviderADD
IsDefaultBOOLEAN NOT NULL DEFAULT FALSE ;
Hope it helps someone