invalidstatement / grit-i18n

Automatically exported from code.google.com/p/grit-i18n
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

Multiple Line <include> Directives Leave Behind the End Tag #19

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Put in a directive like the following:
<include
    src="foobaz.html"
</include>
2. Run the grit tool on that file
3. Observe the </include> is left behind

What is the expected output? What do you see instead?
</include> should no longer be there. It should have been removed when the file 
was inlined.

What version of the product are you using? On what operating system?
r126

Please provide any additional information below.
The proposed fix is below:

For the tags that get replaced wholesale, change the .*> at the end to .*?> and 
use the modifier re.DOTALL to include newlines.

--- grit/format/html_inline.py  (revision 126)
+++ grit/format/html_inline.py  (working copy)
@@ -33,10 +33,10 @@
 # Used by DoInline to replace various links with inline content.
 _STYLESHEET_RE = lazy_re.compile(
     '<link rel="stylesheet"[^>]+?href="(?P<filename>[^"]*)".*?>',
-    re.MULTILINE)
+    re.DOTALL)
 _INCLUDE_RE = lazy_re.compile(
-    '<include[^>]+?src="(?P<filename>[^"\']*)".*>',
-    re.MULTILINE)
+    '<include[^>]+?src="(?P<filename>[^"\']*)".*?>',
+    re.DOTALL)
 _SRC_RE = lazy_re.compile(
     r'<(?!script)(?:[^>]+?\s)src=(?P<quote>")(?P<filename>[^"\']*)\1',
     re.MULTILINE)

Original issue reported on code.google.com by robl...@chromium.org on 13 Jun 2013 at 7:51

GoogleCodeExporter commented 9 years ago
Add a ">" to the end of src="foobaz.html"

Original comment by robl...@chromium.org on 13 Jun 2013 at 7:52

GoogleCodeExporter commented 9 years ago
There is a bug in the regex!

The .*?> is still not enough to capture the end tag. You may need to check for 
both /> and </include>

Original comment by robl...@chromium.org on 28 Jun 2013 at 1:27

GoogleCodeExporter commented 9 years ago
Hi robliao@, do you want to upload a code review to codereview.chromium.org 
that fixes this?  I will be happy to review it and land it for you.  You just 
run [ gcl upload ] or [ git cl upload ] in your checkout of grit-i18n to upload 
the code review.

Original comment by joi@chromium.org on 28 Jun 2013 at 10:31

GoogleCodeExporter commented 9 years ago
I can do that. You'll get the CR mail. I'll send the change around early next 
week.

Original comment by robl...@google.com on 28 Jun 2013 at 4:45