Currently, the validation for the Code snippets (before and after) textareas fields, checks for the presence of the library tracker URL hm.baidu.com/h.js in the submitted code value, since this field shouldn't contain this URL, as it is added automatically by the module.
Since several code types with different library tracker URLs have been added as a supported feature (see related feature request #2076779: Add support for Standard (Legacy) Baidu Analytics tracking code), as of commit 27e35a3, in particular hm.baidu.com/h.js (Standard) and hm.baidu.com/h.js (Asynchronous), the validation should check for both URLs.
Perhaps another validation case could be added for the Standard tracker code library URL hm.baidu.com/hm.js.
Another solution would be to replace the current method to check the presence of the exact string hm.baidu.com/h.js, with the search for a pattern that would cover both URL strings.
Please let me know if you would have any questions, objections, comments, suggestions, recommendations or concerns on any aspects of this bug report, 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
Comment #1
dydave commentedQuick follow-up on this bug report:
Modified the file
baidu_analytics.admin.incand more particularly the functionbaidu_analytics_admin_settings_form_validate(Baidu Analytics Settings form page) to replace the current validation method of code snippets for the presence of the stringhm.baidu.com/h.js, with a search for the pattern:#hm\.baidu\.com/hm?\.js#i, corresponding to the exact Baidu Analytics library tracker URLs that should be rejected.If a match for this pattern is found in submitted code, then a validation error message is prompted to users to let them know the code provided by Baidu Analytics is actually automatically generated by the module and doesn't need to be added here:
I went ahead and committed the changes against the 7.x-1.x branch at 634551a.
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 634551a (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 bug report in general, I would be glad to provide more information or explain in more details.
Special thanks to @xiukun.zhou for his great help on this issue and coming up with an appropriate regex pattern to match with both URL strings.
Thanks in advance to everyone for your testing, reviews, feedback and comments on this issue.
Cheers!