From 597233aacf56bdcf445b2493884ece4d95fcf79a Mon Sep 17 00:00:00 2001
From: Natalie Weizenbaum <nweiz@google.com>
Date: Wed, 21 Oct 2015 14:06:21 -0700
Subject: [PATCH] Fix a bug in pubspec parsing.

We didn't properly check for no sources in a dependency, which caused a
crash for some invalid pubspecs.

Closes #1348

R=rnystrom@google.com

Review URL: https://codereview.chromium.org//1417993002 .
---
 lib/src/pubspec.dart   | 2 ++
 test/pubspec_test.dart | 8 ++++++++
 2 files changed, 10 insertions(+)

diff --git a/lib/src/pubspec.dart b/lib/src/pubspec.dart
index 19bd769f..28b1375c 100644
--- a/lib/src/pubspec.dart
+++ b/lib/src/pubspec.dart
@@ -463,6 +463,8 @@ class Pubspec {
         var sourceNames = spec.keys.toList();
         if (sourceNames.length > 1) {
           _error('A dependency may only have one source.', specNode.span);
+        } else if (sourceNames.isEmpty) {
+          _error('A dependency must contain a source.', specNode.span);
         }
 
         sourceName = sourceNames.single;
diff --git a/test/pubspec_test.dart b/test/pubspec_test.dart
index 6a24d8ae..54be75b0 100644
--- a/test/pubspec_test.dart
+++ b/test/pubspec_test.dart
@@ -229,6 +229,14 @@ dependencies:
 ''', (pubspec) => pubspec.dependencies);
     });
 
+    test("throws if there's no source", () {
+      expectPubspecException('''
+dependencies:
+  foo:
+    version: 1.2.3
+''', (pubspec) => pubspec.dependencies);
+    });
+
     test("throws if 'name' is not a string", () {
       expectPubspecException('name: [not, a, string]',
           (pubspec) => pubspec.name);
-- 
GitLab