Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Unified Diff: pkg/polymer/lib/src/build/import_inliner.dart

Issue 394523002: Sanitize library names generated from file paths (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix formatting and update comments Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/polymer/test/build/import_inliner_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/polymer/lib/src/build/import_inliner.dart
diff --git a/pkg/polymer/lib/src/build/import_inliner.dart b/pkg/polymer/lib/src/build/import_inliner.dart
index 366fa37ad925108683e0b3bb3ba69ce6994f4f60..b48dd6f8823b385b616b5563006245ee3d810b1c 100644
--- a/pkg/polymer/lib/src/build/import_inliner.dart
+++ b/pkg/polymer/lib/src/build/import_inliner.dart
@@ -246,7 +246,11 @@ String _libraryNameFor(AssetId id, int suffix) {
var name = '${path.withoutExtension(id.path)}_'
'${path.extension(id.path).substring(1)}';
if (name.startsWith('lib/')) name = name.substring(4);
- name = name.replaceAll('/', '.').replaceAll('-', '_');
+ name = name.split('/').map((part) {
+ part = part.replaceAll(INVALID_LIB_CHARS_REGEX, '_');
+ if (part.startsWith(NUM_REGEX)) part = '_${part}';
+ return part;
+ }).join(".");
return '${id.package}.${name}_$suffix';
}
@@ -293,14 +297,14 @@ class _UrlNormalizer extends TreeVisitor {
/// Counter used to ensure that every library name we inject is unique.
int _count = 0;
-
+
/// Path to the top level folder relative to the transform primaryInput.
/// This should just be some arbitrary # of ../'s.
final String topLevelPath;
_UrlNormalizer(transform, this.sourceId)
: transform = transform,
- topLevelPath =
+ topLevelPath =
'../' * (transform.primaryInput.id.path.split('/').length - 2);
visitElement(Element node) {
@@ -439,7 +443,11 @@ const _urlAttributes = const [
/// When inlining <link rel="stylesheet"> tags copy over all attributes to the
/// style tag except these ones.
-const IGNORED_LINKED_STYLE_ATTRS =
+const IGNORED_LINKED_STYLE_ATTRS =
const ['charset', 'href', 'href-lang', 'rel', 'rev'];
+/// Global RegExp objects for validating generated library names.
+final INVALID_LIB_CHARS_REGEX = new RegExp('[^a-z0-9_]');
+final NUM_REGEX = new RegExp('[0-9]');
+
_getSpan(SourceFile file, AstNode node) => file.span(node.offset, node.end);
« no previous file with comments | « no previous file | pkg/polymer/test/build/import_inliner_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698