/// /// Format messages helper functions /// /** * @var array */ messageDecorators: [{ // SHA-1 Git commit hashes re: /\b([0-9a-f]{7,40})\b/g, /** * Callback method to linkify when needed a SHA-1 hash. * * @param match The expression matched by the regexp * @param p1 The SHA-1 hash candidate * @param offset The position p1 has been found * @param string The full string p1 has been found * @returns {string} */ replaceBy: function replaceBy(match, p1, offset, string) { if (!serversLog.isHash(p1)) { return p1; } return '%1'.replace(/%1/g, p1); } }, { // Tasks, reviews and pastes re: /\b([TDP][0-9]{1,6}(\#[0-9]{1,10})?)\b/g, replaceBy: '$1' }, { // Repositories callsigns re: /\br([A-Z]{3,32})\b/g, replaceBy: 'r$1' }, { // Commits with callsigns re: /\br([A-Z]{3,32}[0-9a-f]{7,40})\b/g, replaceBy: 'r$1' }, { // Code (or SQL query parameter) re: /`(.*?)`/g, replaceBy: '$1' }], /** * Whitelist of known hexadecimal words. * * @var array */ hexadecimalKnownWord: ["added", "ed25519"], /** * Determines if an expression matches a whitelisted hexadecimal word. * * @param word The word to check * @returns {boolean} */ isHexadecimalKnownWord: function isHexadecimalKnownWord(word) { return this.hexadecimalKnownWord.indexOf(word) > -1; }, /** * Determines if the specified expression is probably an hash. * * An hash is anything hexadecimal with at least one digit < 10 * and one digit > 9 (A-F), not matching known vocabulary. * * @param hash * @returns {boolean} */ isHash: function isHash(hash) { if (this.isHexadecimalKnownWord(hash)) { return false; } if (/^\d+$/.test(hash) || /^[a-z]+$/i.test(hash)) { // Contains only letter or digits, // so not a good hash candidate. return false; } return true; },