Skip to content
This repository has been archived by the owner on Dec 18, 2020. It is now read-only.

Commit

Permalink
Fix: work around windows: it has a 2 char next line sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
agroszer committed May 31, 2013
1 parent 09252d8 commit 9c3da8b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ CHANGES
- Made tests compatible with ``zope.browserresource`` 3.11, thus requiring
at least this version.

- Fix: work around windows: it has a 2 char next line sequence


1.3.0 (2009-08-27)
------------------
Expand Down
24 changes: 24 additions & 0 deletions src/z3c/zrtresource/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,27 @@ utilities).
background: url('../img2/mybackground.gif');
}
<BLANKLINE>

Edge case
---------

On windows blank lines were left in the result

>>> open(fn, 'w').write('''\
... some-head
... /* zrt-replace: "../img1" "++resource++/img" */
... /* zrt-replace: "fontName" "Arial, Tahoma" */
... some-in-the-middle
... /* zrt-replace: "../img2" "++resource++/img" */
... some-at-the-end
... ''')

>>> cssFactory = ZRTFileResourceFactory(fn, None, 'site.css')

>>> from zope.publisher.browser import TestRequest
>>> css = cssFactory(TestRequest())

and render the resource:

>>> css.GET().splitlines()
['some-head', 'some-in-the-middle', 'some-at-the-end']
7 changes: 6 additions & 1 deletion src/z3c/zrtresource/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,18 @@ def compile(self):
# Regular Expression to find commands.
regex = re.compile(COMMAND_REGEX %(self.commandStartRegex,
self.commandEndRegex))
nextlinelen = 1
if '\r\n' in self.source:
# work around windows: it has a 2 char next line sequence
nextlinelen = 2

# Find all commands
for match in regex.finditer(self.source):
command, args = match.groups()

# Add the previous text block and update position
bytecode.append((TEXTBLOCK, self.source[pos:match.start()]))
pos = match.end() + 1
pos = match.end() + nextlinelen

# Make sure the command exists
if command not in self.commands:
Expand Down

0 comments on commit 9c3da8b

Please sign in to comment.