From 3372025458651d21246727471294b19cfd2acad1 Mon Sep 17 00:00:00 2001 From: Maciej Pienczyn Date: Tue, 14 Apr 2026 13:12:06 +0200 Subject: [PATCH] fix: B2B classifieds submit + forum URL underscore handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two user-reported regressions: 1. B2B classifieds "Dodaj ogłoszenie" button silently no-op'd. Hidden Quill description textarea had `required` attribute — browser blocked submit but cannot show validation UI on display:none fields. Removed `required`, added empty-content guard in submit handler with explicit alert. 2. Forum auto-linker truncated Google Maps URLs containing two underscores (e.g. forestry_office...g_ep=). Italic regex `_text_` matched across the URL, splitting it with tags. Italic/bold underscore forms now require non-word boundary so URLs and identifiers like my_var_name pass through untouched. Co-Authored-By: Claude Opus 4.6 (1M context) --- templates/classifieds/edit.html | 11 ++++++++--- templates/classifieds/new.html | 15 +++++++++++---- utils/markdown.py | 13 ++++++++----- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/templates/classifieds/edit.html b/templates/classifieds/edit.html index 99ebe86..6ac5a4f 100644 --- a/templates/classifieds/edit.html +++ b/templates/classifieds/edit.html @@ -120,7 +120,7 @@
- +
@@ -185,9 +185,14 @@ var quill = new Quill('#quill-editor', { }); quill.root.innerHTML = {{ classified.description|tojson }}; -document.querySelector('form').addEventListener('submit', function() { +document.querySelector('form').addEventListener('submit', function(e) { var html = quill.root.innerHTML; - if (html === '


') html = ''; + if (html === '


' || quill.getText().trim() === '') { + e.preventDefault(); + alert('Wpisz treść ogłoszenia.'); + quill.focus(); + return; + } document.getElementById('description').value = html; }); diff --git a/templates/classifieds/new.html b/templates/classifieds/new.html index cf66c8d..12b08e0 100755 --- a/templates/classifieds/new.html +++ b/templates/classifieds/new.html @@ -319,7 +319,7 @@
- +
@@ -368,10 +368,17 @@ var quill = new Quill('#quill-editor', { } }); -// Sync Quill content to hidden textarea on form submit -document.querySelector('form').addEventListener('submit', function() { +// Sync Quill content to hidden textarea on form submit + validate non-empty. +// Note: hidden textarea cannot use `required` (browser cannot show validation +// UI on display:none fields, which silently blocks submit). +document.querySelector('form').addEventListener('submit', function(e) { var html = quill.root.innerHTML; - if (html === '


') html = ''; + if (html === '


' || quill.getText().trim() === '') { + e.preventDefault(); + alert('Wpisz treść ogłoszenia.'); + quill.focus(); + return; + } document.getElementById('description').value = html; }); diff --git a/utils/markdown.py b/utils/markdown.py index 5184528..f6dd02e 100644 --- a/utils/markdown.py +++ b/utils/markdown.py @@ -56,13 +56,16 @@ def parse_forum_markdown(text, current_user_name=None): # Inline code (`code`) text = re.sub(r'`([^`]+)`', r'\1', text) - # Bold (**text** or __text__) + # Bold (**text** or __text__) — require non-word boundary on `_` form + # so URLs like `forestry_office` don't get partially bolded. text = re.sub(r'\*\*([^*]+)\*\*', r'\1', text) - text = re.sub(r'__([^_]+)__', r'\1', text) + text = re.sub(r'(^|\W)__([^_\n]+?)__(?=\W|$)', r'\1\2', text) - # Italic (*text* or _text_) - careful not to match bold - text = re.sub(r'(?\1
', text) - text = re.sub(r'(?\1', text) + # Italic (*text* or _text_) — same boundary rule for `_` to avoid + # eating underscores inside URLs (e.g. ?g_ep=...) which corrupted forum + # links. The captured leading char is re-emitted. + text = re.sub(r'(?\1', text) + text = re.sub(r'(^|\W)_(?!_)([^_\n]+?)_(?=\W|$)', r'\1\2', text) # Links [text](url) - only allow http/https def safe_link(match):