dart-lang / pub

The pub command line tool
https://dart.dev/tools/pub/cmd
BSD 3-Clause "New" or "Revised" License
1.05k stars 230 forks source link

Wrong indentation of version for a hosted package is ignored and no exception is thrown #4444

Open Jannik-dev opened 3 hours ago

Jannik-dev commented 3 hours ago

Environment

Problem

I recently discovered that pub get worked fine when the version constraint on a hosted package has a wrong indentation.

This is my example pubspec.yaml (version is indented too much), it essentially acts like no version is specified, which could be quite tricky to track down when the project gets older:

dependencies:
  plugin_platform_interface:
    hosted:
      url: https://pub.dev
      version: 2.1.3

When using the pubspec_parse (version 1.3.0) an error is thrown which I would expect from pub get as well.

Expected behavior

An exception is thrown that there are characters which aren't in used during parsing or that the version has the wrong indentation.

Actual behavior

pub get acts like the version line does not exist.

sigurdm commented 1 hour ago

The pubspec.yaml format is intentionally designed to be open-ended. Meaning we (mostly) leave extra properties alone. This leads to issues like this.

We are doing some spell checking on top-level properties (though only when publishing) if they have a short edit-distance to known properties.

Perhaps there is some special casing we could do for things like this.