Skip to content

Commit b6d20d8

Browse files
Copilotmekarpeles
andcommitted
Final refinements - improve pattern matching and add constant for cookie expiry
Co-authored-by: mekarpeles <978325+mekarpeles@users.noreply.github.com>
1 parent 72c54a0 commit b6d20d8

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

openlibrary/plugins/upstream/account.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,13 +1310,14 @@ class account_verify_human(delegate.page):
13101310
Sets the vf=1 cookie and redirects back to the original URL.
13111311
"""
13121312
path = "/account/verify_human"
1313+
1314+
# Cookie expires in 30 days
1315+
VERIFICATION_COOKIE_EXPIRES_SECONDS = 30 * 24 * 60 * 60
13131316

13141317
def POST(self):
13151318
"""Handle verification request."""
13161319
# Set the verification cookie (vf=1)
1317-
# Cookie expires in 30 days
1318-
expires = 30 * 24 * 60 * 60
1319-
web.setcookie('vf', '1', expires=expires)
1320+
web.setcookie('vf', '1', expires=self.VERIFICATION_COOKIE_EXPIRES_SECONDS)
13201321

13211322
# Track verification success
13221323
stats.increment('ol.stats.verify_human.verified')

openlibrary/plugins/worksearch/code.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,6 @@ def _is_expensive_search(self, i):
805805
q = i.get('q', '').strip()
806806

807807
# Check for specialized Solr syntax patterns
808-
# We need to be careful not to match URLs
809808
expensive_patterns = [
810809
r'language:', # language: queries
811810
r'\*:\*', # Wildcard queries
@@ -819,9 +818,9 @@ def _is_expensive_search(self, i):
819818
if re.search(pattern, q, re.IGNORECASE):
820819
return True
821820

822-
# Check for field-specific queries, but exclude common URL schemes
823-
# This pattern matches word:something but not http://, https://, ftp://, etc.
824-
if re.search(r'(?<!http)(?<!https)(?<!ftp)(?<!mailto)\b\w+:(?!//)', q, re.IGNORECASE):
821+
# Check for field-specific queries while excluding URL schemes
822+
# Matches patterns like 'field:value' but not 'http://', 'https://', 'ftp://', 'mailto:'
823+
if re.search(r'(?<![:/])\b(?!(?:https?|ftp|mailto)://)\w+:', q, re.IGNORECASE):
825824
return True
826825

827826
# Check if language filter is being used

openlibrary/templates/lib/challenge.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ <h1>$_("Human Verification")</h1>
1616
var button = document.getElementById('verify-human-btn');
1717
var verifyingText = $:json.dumps(_("Verifying..."));
1818
var errorText = $:json.dumps(_("Verification failed. Please try again."));
19-
var buttonText = $:json.dumps(_("Verify you are human"));
19+
var originalText = button.textContent;
2020

2121
button.addEventListener('click', function() {
2222
button.disabled = true;
@@ -40,7 +40,7 @@ <h1>$_("Human Verification")</h1>
4040
console.error('Verification error:', error);
4141
alert(errorText);
4242
button.disabled = false;
43-
button.textContent = buttonText;
43+
button.textContent = originalText;
4444
});
4545
});
4646
})();

0 commit comments

Comments
 (0)