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

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: 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
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..18e2c37dcd8e43cb947439ee8133056fdbd3bcf5 100644
--- a/pkg/polymer/lib/src/build/import_inliner.dart
+++ b/pkg/polymer/lib/src/build/import_inliner.dart
@@ -246,7 +246,12 @@ 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.replaceAll('-', '_');
Siggi Cherem (dart-lang) 2014/07/14 19:34:11 alternatively, we could remove this line and make
jakemac 2014/07/14 20:30:24 Actually I kind of like that idea, less likelihood
+ 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 +298,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 +444,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') | pkg/polymer/test/build/import_inliner_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698