Merge lp:~therp-nl/openupgrade-addons/7.0-wiki-nobacktracking-regex into lp:openupgrade-addons

Proposed by Holger Brunn (Therp)
Status: Merged
Merged at revision: 8174
Proposed branch: lp:~therp-nl/openupgrade-addons/7.0-wiki-nobacktracking-regex
Merge into: lp:openupgrade-addons
Diff against target: 55 lines (+32/-8)
1 file modified
document_page/migrations/7.0.1.0.1/post-migration.py (+32/-8)
To merge this branch: bzr merge lp:~therp-nl/openupgrade-addons/7.0-wiki-nobacktracking-regex
Reviewer Review Type Date Requested Status
Ronald Portier (Therp) code review and test Approve
Pedro Manuel Baeza code review Approve
Sandy Carter (http://www.savoirfairelinux.com) (community) code review, no test Approve
Review via email: mp+238872@code.launchpad.net

Description of the change

This branch avoids using regexes in cases where backtracking can become so expensive that it seems like a deadlock, i.e. with

re.compile("'''''(([^']|([^']'{0,4}[^']))+)'''''").sub("<b><i>\1</i></b>", "'''''test'''' hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world")

Note that this occurs with all regexes of this kind in the case it's a malformed wiki syntax

To post a comment you must log in.
Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote :

LGTM +1

review: Approve (code review, no test)
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

LGTM

review: Approve (code review)
Revision history for this message
Ronald Portier (Therp) (rportier1962) wrote :

Tested conversion in a separate function and code review

review: Approve (code review and test)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'document_page/migrations/7.0.1.0.1/post-migration.py'
--- document_page/migrations/7.0.1.0.1/post-migration.py 2014-09-15 07:43:23 +0000
+++ document_page/migrations/7.0.1.0.1/post-migration.py 2014-10-20 12:48:46 +0000
@@ -111,9 +111,6 @@
111re_ol_li = re.compile("^(\*\*+|#+):? ")111re_ol_li = re.compile("^(\*\*+|#+):? ")
112re_ul_ol_li = re.compile("^(\*+|#+):? ")112re_ul_ol_li = re.compile("^(\*+|#+):? ")
113re_youtube = re.compile("^(https?://)?(www\.)?youtube.com/(watch\?(.*)v=|embed/)([^&]+)")113re_youtube = re.compile("^(https?://)?(www\.)?youtube.com/(watch\?(.*)v=|embed/)([^&]+)")
114re_b_i = re.compile("'''''(([^']|([^']('{1,4})?[^']))+)'''''")
115re_b = re.compile("'''(([^']|([^'](''?)?[^']))+)'''")
116re_i = re.compile("''(([^']|([^']'?[^']))+)''")
117114
118115
119class Wiky:116class Wiky:
@@ -316,9 +313,36 @@
316 break313 break
317314
318 # Bold, Italics, Emphasis315 # Bold, Italics, Emphasis
319 wikitext = re_b_i.sub("<b><i>\1</i></b>", wikitext)316 head = ''
320 wikitext = re_b.sub("<b>\1</b>", wikitext)317 tail = wikitext
321 wikitext = re_i.sub("<i>\1</i>", wikitext)318 while tail:
322319 quote_pos = tail.find("'")
323 return wikitext320 if quote_pos > -1:
321 head += tail[:quote_pos]
322 tail = tail[quote_pos:]
323 pos = 0
324 while pos < len(tail) and tail[pos] == "'":
325 pos += 1
326 if pos == 2 or pos == 3 or pos == 5:
327 endquote_pos = tail.find("'"*pos, pos)
328 if endquote_pos > -1:
329 text = tail[pos:endquote_pos]
330 if pos == 2:
331 text = '<i>%s</i>' % text
332 elif pos == 3:
333 text = '<b>%s</b>' % text
334 elif pos == 5:
335 text = '<b><i>%s</i></b>' % text
336 head += text
337 tail = tail[endquote_pos + pos:]
338 else:
339 head += tail[:pos]
340 tail = tail[pos:]
341 else:
342 head += tail[:pos]
343 tail = tail[pos:]
344 else:
345 head += tail
346 tail = ''
347 return head
324# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:348# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

Subscribers

People subscribed via source and target branches