Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

headerid extension patch #99

Closed
thread13 opened this issue May 15, 2012 · 0 comments
Closed

headerid extension patch #99

thread13 opened this issue May 15, 2012 · 0 comments

Comments

@thread13
Copy link

Basically it is an update for the issue 54: an empty string is still considered to be a valid unique id.

As the code has gone from toc.py to, I guess, headerid.py, here is a new patch:

--- headerid.py 2012-05-15 15:36:49.000000000 +1000
+++ headerid.py.new 2012-05-15 16:04:25.000000000 +1000
@@ -97,7 +97,7 @@

 def unique(id, ids):
     """ Ensure id is unique in set of ids. Append '_1', '_2'... if not """
-    while id in ids:
+    while id in ids or not id :
         m = IDCOUNT_RE.match(id)
         if m:
             id = '%s_%d'% (m.group(1), int(m.group(2))+1)

basically anything that will check for a non-empty id value will do, e.g. setting

id = id or '_0'

before the while loop, etc ; I assume that the id in ids check is more likely to be true, thus the suggested version .

Again, the point was that for non-ascii headers slugify() returns a completely empty string ( as one can clearly see from its code ), so it looks as a good idea to turn it to something non-empty ; which function -- "slugify()" or "unique()" -- should perform that check, is of course completely a matter of the author's choice -- but as the "slugify()" function could be currently, AFAIR, provided by the user -- it might be a good idea to perform a non-zero check afterwards, i.e. in "unique()" .

Bottom line: here is a patch for the current version for the issue 54 )

@waylan waylan closed this as completed in 396daf3 May 24, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants