cmpilato / thotkeeper

ThotKeeper — cross-platform personal daily journaling

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

/// Tag produces empty entries in tree

GoogleCodeExporter opened this issue · comments

What steps will reproduce the problem?
1. edit entry 
2. set one tag to '/tag' or 'tag/'
3. save & look at tag tree

What is the expected output? What do you see instead?
empty parts of tag hierarchy should be ignored, but instead are retained
into the tag tree as empty labels (which are still easy to work with due to
expand/collapse arrows, but look a bit daft).


Original issue reported on code.google.com by smith.d...@gmail.com on 3 May 2008 at 6:11

So, we should sanitize tags like so:

   tag = '/'.join(filter(None, tag.split('/')))

Original comment by cmpilato on 5 May 2008 at 3:07

I had to try it out to see what it actually did (I couldn't quite get my head 
around
it), but that does seem to be the right thing to do.

Have now checked in changes based on this as revision 65

Original comment by smith.d...@gmail.com on 5 May 2008 at 5:10

  • Changed state: Fixed
The code above?  It basically splits the string on the '/' character, which 
produces
a list of string segments, some of which may be empty.  The filter function 
takes a
list, and returns the same list minus any members that don't evaluate to True.  
Empty
strings don't evaluate to True, so they get tossed.  Finally, we rejoin the 
segments
that remain with the '/' delimiter.

>>> tag = '///this//is/my//tag///'
>>> list = tag.split('/')
>>> list
['', '', '', 'this', '', 'is', 'my', '', 'tag', '', '', '']
>>> list = filter(None, list)
>>> list
['this', 'is', 'my', 'tag']
>>> tag = '/'.join(list)
>>> tag
'this/is/my/tag'
>>> 

Original comment by cmpilato on 5 May 2008 at 5:35

It was the '/'.join(...) bit that confused me (the rest I understood).

I guessed it meant: start with '/' and then join the array elements together and
append them onto the end (which would actually be: '/' + ''.join(...)) and 
*that*
would not have been what we wanted. This article cleared up my confusion:
http://www.faqs.org/docs/diveintopython/odbchelper_join.html

My re-jig of it trims all the elements before filtering them; this throws away 
both
surrounding whitespace and tag elements that only contain whitespace.

Original comment by smith.d...@gmail.com on 5 May 2008 at 5:46

Original comment by cmpilato on 7 May 2008 at 5:48

  • Added labels: Milestone-Version0.2.0

Original comment by cmpilato on 20 May 2008 at 5:05

  • Added labels: Milestone-0.2.0