Currently, a Baidu Map API Key is provided as a string of 32 hexadecimal characters, such as 0123456789abcdef0123456789abcdef and module doesn't seem to have any validation rule for any specific format.

We could add a [FORM_ID]_validate validation callback to the baidu_map.admin.inc to only allow: 0 to 9 and a to f lower or upper case characters, with a length of 32 characters. Otherwise, an error message could be displayed to let users know about the format to be provided for the Baidu API Key.
This would prevent any potentially incomplete or "wrong" key to be mistakenly or unintentionally input and saved by a user while configuring the module.

Please let me know if you would have any questions, objections, comments, suggestions, recommendations or concerns on any aspects of feature request, I would be glad to provide more information or explain in more details.

Any questions, feedback, testing, changes, ideas or recommendations would be highly appreciated.
Thanks to all in advance.

Comments

xiukun.zhou’s picture

Status: Active » Fixed

Quick follow-up on this feature request:

Added baidu_map_settings_validate validation callback to the baidu_map.admin.inc file to ensure submitted Baidu Map API Key contains exactly 32 hexadecimal characters and display an error message otherwise.
The value submitted is now tested with a regular expression:

<?php
preg_match('/^[a-fA-F0-9]{32}$/', $api_key)
?>

to only allow: 0 to 9 and a to f lower or upper case characters, with a length of 32 characters.

I went ahead and committed the changes against the 7.x-1.x branch at 775bc5b.

I allowed myself to mark this issue as fixed for now, but feel free to re-open it, or post a new ticket, at any time if you have any further objections with this ticket or related commit 775bc5b (we would surely be happy to hear your feedback).

Please let me know if you would have any further comments, feedback, questions, issues, objections, suggestions or concerns on the commit or this feature request in general, I would be glad to provide more information or explain in more details.

Special thanks to @DYdave for his great help picking up this important improvement.
Thanks in advance to everyone for your testing, reviews, feedback and comments on this issue.
Cheers!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.