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

Side by Side Diff: pkg/analyzer/test/src/summary/summary_common.dart

Issue 2665213003: Encode URIs stored in unlinked summaries to make them Uri.parse() safe. (Closed)
Patch Set: Created 3 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.test.src.summary.summary_common; 5 library analyzer.test.src.summary.summary_common;
6 6
7 import 'package:analyzer/analyzer.dart'; 7 import 'package:analyzer/analyzer.dart';
8 import 'package:analyzer/dart/ast/ast.dart'; 8 import 'package:analyzer/dart/ast/ast.dart';
9 import 'package:analyzer/error/listener.dart'; 9 import 'package:analyzer/error/listener.dart';
10 import 'package:analyzer/src/dart/scanner/reader.dart'; 10 import 'package:analyzer/src/dart/scanner/reader.dart';
(...skipping 6463 matching lines...) Expand 10 before | Expand all | Expand 10 after
6474 addNamedSource('/a.dart', 'library my.lib;'); 6474 addNamedSource('/a.dart', 'library my.lib;');
6475 String uriString = '"a.dart"'; 6475 String uriString = '"a.dart"';
6476 String libraryText = 'export $uriString;'; 6476 String libraryText = 'export $uriString;';
6477 serializeLibraryText(libraryText); 6477 serializeLibraryText(libraryText);
6478 var unlinkedExports = unlinkedUnits[0].publicNamespace.exports; 6478 var unlinkedExports = unlinkedUnits[0].publicNamespace.exports;
6479 expect(unlinkedExports, hasLength(1)); 6479 expect(unlinkedExports, hasLength(1));
6480 expect(unlinkedExports[0].uri, 'a.dart'); 6480 expect(unlinkedExports[0].uri, 'a.dart');
6481 expect(unlinkedExports[0].configurations, isEmpty); 6481 expect(unlinkedExports[0].configurations, isEmpty);
6482 } 6482 }
6483 6483
6484 test_export_uri_invalid() {
6485 allowMissingFiles = true;
6486 String uri = '[invalid uri]';
6487 String libraryText = 'export "$uri";';
6488 serializeLibraryText(libraryText);
6489 UnlinkedPublicNamespace publicNamespace = unlinkedUnits[0].publicNamespace;
6490 expect(publicNamespace.exports, hasLength(1));
6491 expect(publicNamespace.exports[0].uri, Uri.encodeFull(uri));
6492 }
6493
6484 test_export_uri_nullStringValue() { 6494 test_export_uri_nullStringValue() {
6485 String libraryText = r''' 6495 String libraryText = r'''
6486 export "${'a'}.dart"; 6496 export "${'a'}.dart";
6487 '''; 6497 ''';
6488 serializeLibraryText(libraryText); 6498 serializeLibraryText(libraryText);
6489 var unlinkedExports = unlinkedUnits[0].publicNamespace.exports; 6499 var unlinkedExports = unlinkedUnits[0].publicNamespace.exports;
6490 expect(unlinkedExports, hasLength(1)); 6500 expect(unlinkedExports, hasLength(1));
6491 expect(unlinkedExports[0].uri, ''); 6501 expect(unlinkedExports[0].uri, '');
6492 expect(unlinkedExports[0].configurations, isEmpty); 6502 expect(unlinkedExports[0].configurations, isEmpty);
6493 } 6503 }
(...skipping 1903 matching lines...) Expand 10 before | Expand all | Expand 10 after
8397 8407
8398 test_import_uri() { 8408 test_import_uri() {
8399 String uriString = '"dart:async"'; 8409 String uriString = '"dart:async"';
8400 String libraryText = 'import $uriString; Future x;'; 8410 String libraryText = 'import $uriString; Future x;';
8401 serializeLibraryText(libraryText); 8411 serializeLibraryText(libraryText);
8402 // Second import is the implicit import of dart:core 8412 // Second import is the implicit import of dart:core
8403 expect(unlinkedUnits[0].imports, hasLength(2)); 8413 expect(unlinkedUnits[0].imports, hasLength(2));
8404 expect(unlinkedUnits[0].imports[0].uri, 'dart:async'); 8414 expect(unlinkedUnits[0].imports[0].uri, 'dart:async');
8405 } 8415 }
8406 8416
8417 test_import_uri_invalid() {
8418 allowMissingFiles = true;
8419 String uri = '[invalid uri]';
8420 String libraryText = 'import "$uri";';
8421 serializeLibraryText(libraryText);
8422 // Second import is the implicit import of dart:core
8423 expect(unlinkedUnits[0].imports, hasLength(2));
8424 expect(unlinkedUnits[0].imports[0].uri, Uri.encodeFull(uri));
8425 }
8426
8407 test_import_uri_nullStringValue() { 8427 test_import_uri_nullStringValue() {
8408 String libraryText = r''' 8428 String libraryText = r'''
8409 import "${'a'}.dart"; 8429 import "${'a'}.dart";
8410 '''; 8430 ''';
8411 serializeLibraryText(libraryText); 8431 serializeLibraryText(libraryText);
8412 // Second import is the implicit import of dart:core 8432 // Second import is the implicit import of dart:core
8413 expect(unlinkedUnits[0].imports, hasLength(2)); 8433 expect(unlinkedUnits[0].imports, hasLength(2));
8414 expect(unlinkedUnits[0].imports[0].uri, ''); 8434 expect(unlinkedUnits[0].imports[0].uri, '');
8415 } 8435 }
8416 8436
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after
9595 expect(unlinkedUnits[0].parts[0].uriEnd, text.indexOf('; // <-part')); 9615 expect(unlinkedUnits[0].parts[0].uriEnd, text.indexOf('; // <-part'));
9596 } 9616 }
9597 9617
9598 test_part_isPartOf() { 9618 test_part_isPartOf() {
9599 addNamedSource('/a.dart', 'part of foo; class C {}'); 9619 addNamedSource('/a.dart', 'part of foo; class C {}');
9600 serializeLibraryText('library foo; part "a.dart";'); 9620 serializeLibraryText('library foo; part "a.dart";');
9601 expect(unlinkedUnits[0].isPartOf, isFalse); 9621 expect(unlinkedUnits[0].isPartOf, isFalse);
9602 expect(unlinkedUnits[1].isPartOf, isTrue); 9622 expect(unlinkedUnits[1].isPartOf, isTrue);
9603 } 9623 }
9604 9624
9625 test_part_uri_invalid() {
9626 allowMissingFiles = true;
9627 String uri = '[invalid uri]';
9628 String libraryText = 'part "$uri";';
9629 serializeLibraryText(libraryText);
9630 UnlinkedPublicNamespace publicNamespace = unlinkedUnits[0].publicNamespace;
9631 expect(publicNamespace.parts, hasLength(1));
9632 expect(publicNamespace.parts[0], Uri.encodeFull(uri));
9633 }
9634
9605 test_parts_defining_compilation_unit() { 9635 test_parts_defining_compilation_unit() {
9606 serializeLibraryText(''); 9636 serializeLibraryText('');
9607 expect(linked.units, hasLength(1)); 9637 expect(linked.units, hasLength(1));
9608 expect(unlinkedUnits[0].publicNamespace.parts, isEmpty); 9638 expect(unlinkedUnits[0].publicNamespace.parts, isEmpty);
9609 } 9639 }
9610 9640
9611 test_parts_included() { 9641 test_parts_included() {
9612 addNamedSource('/part1.dart', 'part of my.lib;'); 9642 addNamedSource('/part1.dart', 'part of my.lib;');
9613 String partString = '"part1.dart"'; 9643 String partString = '"part1.dart"';
9614 String libraryText = 'library my.lib; part $partString;'; 9644 String libraryText = 'library my.lib; part $partString;';
(...skipping 1093 matching lines...) Expand 10 before | Expand all | Expand 10 after
10708 class _PrefixExpectation { 10738 class _PrefixExpectation {
10709 final ReferenceKind kind; 10739 final ReferenceKind kind;
10710 final String name; 10740 final String name;
10711 final String absoluteUri; 10741 final String absoluteUri;
10712 final String relativeUri; 10742 final String relativeUri;
10713 final int numTypeParameters; 10743 final int numTypeParameters;
10714 10744
10715 _PrefixExpectation(this.kind, this.name, 10745 _PrefixExpectation(this.kind, this.name,
10716 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0}); 10746 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0});
10717 } 10747 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698