Skip to content

Validate files don't differ in case only #3740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/src/validator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import 'validator/dependency_override.dart';
import 'validator/deprecated_fields.dart';
import 'validator/directory.dart';
import 'validator/executable.dart';
import 'validator/file_case.dart';
import 'validator/flutter_constraint.dart';
import 'validator/flutter_plugin_format.dart';
import 'validator/gitignore.dart';
Expand Down Expand Up @@ -136,6 +137,7 @@ abstract class Validator {
required List<String> errors,
}) async {
var validators = [
FileCaseValidator(),
AnalyzeValidator(),
GitignoreValidator(),
PubspecValidator(),
Expand Down
32 changes: 32 additions & 0 deletions lib/src/validator/file_case.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';

import 'package:collection/collection.dart';

import '../validator.dart';

/// Validates that a package files all are unique even after case-normalization.
class FileCaseValidator extends Validator {
@override
Future validate() async {
final lowerCaseToFile = <String, String>{};
for (final file in files.sorted()) {
final lowerCase = file.toLowerCase();
final existing = lowerCaseToFile[lowerCase];
if (existing != null) {
errors.add('''
The file $file and $existing only differ in capitalization.

This is not supported across platforms.

Try renaming one of them.
''');
break;
}
lowerCaseToFile[lowerCase] = file;
}
}
}
42 changes: 42 additions & 0 deletions test/validator/file_case_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// These tests only work on case-sensitive file systems (ie. only on linux).
@OnPlatform({
'windows': Skip('Windows file system is case-insensitive'),
'mac-os': Skip('MacOS file system is case-insensitive')
})

import 'package:pub/src/exit_codes.dart';
import 'package:test/test.dart';

import '../descriptor.dart' as d;
import '../test_pub.dart';

Future<void> expectValidation(error, int exitCode) async {
await runPub(
error: error,
args: ['publish', '--dry-run'],
workingDirectory: d.path(appPath),
exitCode: exitCode,
);
}

late d.DirectoryDescriptor fakeFlutterRoot;

void main() {
test('Recognizes files that only differ in capitalization.', () async {
await d.validPackage.create();
await d.dir(appPath, [d.file('Pubspec.yaml')]).create();
await expectValidation(
allOf(
contains('Package validation found the following error:'),
contains(
'The file ./pubspec.yaml and ./Pubspec.yaml only differ in capitalization.',
),
),
DATA,
);
});
}