Commit 168903a8 authored by Dan Beam's avatar Dan Beam Committed by Commit Bot

Strip // in front of <include> for single-line JS comments

We've previously relied on almost all code in Chromium to start
with a license header, and therefore placing <include> behind
single-line JS comments, as in:

  // <include src="blah.js">

Harmlessly expands to:

  // // Copyright the Chromium Authors

But this is not always the case, and is kind of a hack. So
instead, detect the case of "// " in front of a <include> and
remove it. So that same "// <include" becomes:

  // Copyright the Chromium Authors

or in the case that the file doesn't have a copyright, the
first line of source code (like in dom_distiller).

Sure, it adds more magic to the system, but it's probably fine.

R=dpapad@chromium.org

Fixed: 1021374
Change-Id: Ie7dbf9607c0a78caa20d0e60662efc9d81f88f39
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1898870Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Dan Beam <dbeam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712725}
parent 39d15481
......@@ -49,8 +49,8 @@ _STYLESHEET_RE = lazy_re.compile(
r'<link rel="stylesheet"[^>]+?href="(?P<filename>[^"]*)".*?>(\s*</link>)?',
re.DOTALL)
_INCLUDE_RE = lazy_re.compile(
r'<include[^>]+?src=("(?P<file1>[^">]*)"|\'(?P<file2>[^\'>]*)\').*?>'
r'(\s*</include>)?',
r'(?P<comment>\/\/ )?<include[^>]+?'
r'src=("(?P<file1>[^">]*)"|\'(?P<file2>[^\'>]*)\').*?>(\s*</include>)?',
re.DOTALL)
_SRC_RE = lazy_re.compile(
r'<(?!script)(?:[^>]+?\s)src="(?!\[\[|{{)(?P<filename>[^"\']*)"',
......
......@@ -538,7 +538,7 @@ class HtmlInlineUnittest(unittest.TestCase):
'other.js': '// Copyright somebody\nalert(1);',
}
expected_inlined = '// // Copyright somebody\nalert(1);'
expected_inlined = '// Copyright somebody\nalert(1);'
source_resources = set()
tmp_dir = util.TempDir(files)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment