From: Ardis Lu Date: Tue, 9 Jan 2024 06:33:28 +0000 (-0800) Subject: Add strict mode X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=7067ca5d7bcba9e16c2c4fa480e7018f871f685b;p=event-hashes Add strict mode --- diff --git a/index.html b/index.html index b19ca45..c9e14af 100644 --- a/index.html +++ b/index.html @@ -161,14 +161,16 @@ // From noble-hashes v1.3.3 import { keccak256 } from '/keccak256.js'; - function normalizeEvent(event) { + function normalizeEvent(event, strict = false) { // Clean all characters that definitely do not affect the signature const commentIndex = event.indexOf('//'); event = commentIndex === -1 ? event : event.substring(0, commentIndex); event = event.trim(); // Split the event name and the event topics - const eventRegex = /^(event )?(?[a-zA-Z$_][a-zA-Z0-9$_]*)\((?.*?)(?!.+\))/; + const eventRegex = strict ? + /^(event )(?[a-zA-Z$_][a-zA-Z0-9$_]*)\((?.*?)(?!.+\))/ : + /^(event )?(?[a-zA-Z$_][a-zA-Z0-9$_]*)\((?.*?)(?!.+\))/; const { name, topics } = eventRegex.exec(event).groups; // Drop parameter names and extraneous whitespace, if there are any. Preserves tuple parentheses. @@ -198,13 +200,18 @@ function getEvents(code) { const events = new Set(); + let strict = false; for (let line of code.split('\n')) { line = line.trim(); if (line === '') { continue; } + if (line.substring(0, 8) === 'contract' || line.substring(0, 17) === 'abstract contract') { + strict = true; + continue; + } try { - const normalizedEvent = normalizeEvent(line); + const normalizedEvent = normalizeEvent(line, strict); events.add(normalizedEvent); } catch {