Skip to content

Commit d1bb4a0

Browse files
authored
Allow a BOM at the beginning of a document (#441)
This was only breaking in JS because apparently dart:io automatically filters out BOMs. Closes #437
1 parent 0f7f9e6 commit d1bb4a0

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@
2121
`\E9clair` are parsed to the same value. See
2222
[the proposal][identifier-escapes] for details.
2323

24+
* Don't choke on a [byte-order mark][] at the beginning of a document when
25+
running in JavaScript.
26+
2427
[math functions]: https://drafts.csswg.org/css-values/#math-function
2528
[css-import]: https://github.com/sass/language/blob/master/accepted/css-imports.md
2629
[css-min-max]: https://github.com/sass/language/blob/master/accepted/min-max.md
2730
[media-ranges]: https://github.com/sass/language/blob/master/accepted/media-ranges.md
2831
[identifier-escapes]: https://github.com/sass/language/blob/master/accepted/identifier-escapes.md
32+
[byte-order mark]: https://en.wikipedia.org/wiki/Byte_order_mark
2933

3034
### Command-Line Interface
3135

lib/src/parse/stylesheet.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ abstract class StylesheetParser extends Parser {
6565
Stylesheet parse() {
6666
return wrapSpanFormatException(() {
6767
var start = scanner.state;
68+
// Allow a byte-order mark at the beginning of the document.
69+
scanner.scanChar(0xFEFF);
6870
var statements = this.statements(() => _statement(root: true));
6971
scanner.expectDone();
7072
return new Stylesheet(statements, scanner.spanFrom(start),

test/cli/shared.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// https://opensource.org/licenses/MIT.
44

55
import 'dart:async';
6+
import 'dart:io';
67

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

48+
// Regression test for #437.
49+
test("compiles a Sass file with a BOM to CSS", () async {
50+
await d.file("test.scss", "\uFEFF\$color: red;").create();
51+
52+
var sass = await runSass(["test.scss"]);
53+
expect(sass.stdout, emitsDone);
54+
await sass.shouldExit(0);
55+
});
56+
4757
// On Windows, this verifies that we don't consider the colon after a drive
4858
// letter to be an `input:output` separator.
4959
test("compiles an absolute Sass file to CSS", () async {

0 commit comments

Comments
 (0)