Skip to content

Commit

Permalink
Allow a BOM at the beginning of a document (#441)
Browse files Browse the repository at this point in the history
This was only breaking in JS because apparently dart:io automatically
filters out BOMs.

Closes #437
  • Loading branch information
nex3 committed Aug 10, 2018
1 parent 0f7f9e6 commit d1bb4a0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@
`\E9clair` are parsed to the same value. See
[the proposal][identifier-escapes] for details.

* Don't choke on a [byte-order mark][] at the beginning of a document when
running in JavaScript.

[math functions]: https://drafts.csswg.org/css-values/#math-function
[css-import]: https://github.com/sass/language/blob/master/accepted/css-imports.md
[css-min-max]: https://github.com/sass/language/blob/master/accepted/min-max.md
[media-ranges]: https://github.com/sass/language/blob/master/accepted/media-ranges.md
[identifier-escapes]: https://github.com/sass/language/blob/master/accepted/identifier-escapes.md
[byte-order mark]: https://en.wikipedia.org/wiki/Byte_order_mark

### Command-Line Interface

Expand Down
2 changes: 2 additions & 0 deletions lib/src/parse/stylesheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ abstract class StylesheetParser extends Parser {
Stylesheet parse() {
return wrapSpanFormatException(() {
var start = scanner.state;
// Allow a byte-order mark at the beginning of the document.
scanner.scanChar(0xFEFF);
var statements = this.statements(() => _statement(root: true));
scanner.expectDone();
return new Stylesheet(statements, scanner.spanFrom(start),
Expand Down
10 changes: 10 additions & 0 deletions test/cli/shared.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// https://opensource.org/licenses/MIT.

import 'dart:async';
import 'dart:io';

import 'package:path/path.dart' as p;
import 'package:test/test.dart';
Expand Down Expand Up @@ -44,6 +45,15 @@ void sharedTests(Future<TestProcess> runSass(Iterable<String> arguments)) {
await sass.shouldExit(0);
});

// Regression test for #437.
test("compiles a Sass file with a BOM to CSS", () async {
await d.file("test.scss", "\uFEFF\$color: red;").create();

var sass = await runSass(["test.scss"]);
expect(sass.stdout, emitsDone);
await sass.shouldExit(0);
});

// On Windows, this verifies that we don't consider the colon after a drive
// letter to be an `input:output` separator.
test("compiles an absolute Sass file to CSS", () async {
Expand Down

0 comments on commit d1bb4a0

Please sign in to comment.