@@ -29,7 +29,23 @@ describe('removeBomStream', function () {
29
29
) ;
30
30
} ) ;
31
31
32
- it ( 'removes the BOM from a UTF8 buffer' , function ( done ) {
32
+ it ( 'ignores UTF8 buffer without a BOM even if first chunk is shorter than 7 chars but second and subsequent are larger' , function ( done ) {
33
+ var filepath = path . join ( __dirname , './fixtures/test.txt' ) ;
34
+ var fileContent = fs . readFileSync ( filepath , 'utf-8' ) ;
35
+
36
+ var rmBom = removeBomStream ( ) ;
37
+ var output = '' ;
38
+ rmBom . on ( 'data' , function ( d ) {
39
+ output += d . toString ( ) ;
40
+ } ) ;
41
+ rmBom . write ( Buffer . from ( fileContent . slice ( 0 , 5 ) ) ) ;
42
+ rmBom . write ( Buffer . from ( fileContent . slice ( 5 ) ) ) ;
43
+
44
+ expect ( output ) . toEqual ( fileContent ) ;
45
+ done ( ) ;
46
+ } ) ;
47
+
48
+ it ( 'removes the BOM from a UTF8 buffer' , function ( done ) {
33
49
var filepath = path . join ( __dirname , './fixtures/bom-utf8.txt' ) ;
34
50
35
51
var expected = fs . readFileSync ( filepath ) . slice ( 3 ) ;
@@ -81,7 +97,23 @@ describe('removeBomStream', function () {
81
97
) ;
82
98
} ) ;
83
99
84
- it ( 'does not remove the BOM from a UTF16BE buffer' , function ( done ) {
100
+ it ( 'remove the BOM from a UTF8 buffer even if first chunk is shorter than 7 chars but second and subsequent are larger' , function ( done ) {
101
+ var filepath = path . join ( __dirname , './fixtures/bom-utf8.txt' ) ;
102
+ var fileContent = fs . readFileSync ( filepath , 'utf-8' ) ;
103
+
104
+ var rmBom = removeBomStream ( ) ;
105
+ var output = '' ;
106
+ rmBom . on ( 'data' , function ( d ) {
107
+ output += d . toString ( ) ;
108
+ } ) ;
109
+ rmBom . write ( Buffer . from ( fileContent . slice ( 0 , 5 ) ) ) ;
110
+ rmBom . write ( Buffer . from ( fileContent . slice ( 5 ) ) ) ;
111
+
112
+ expect ( output ) . toEqual ( fileContent . slice ( 1 ) ) ;
113
+ done ( ) ;
114
+ } ) ;
115
+
116
+ it ( 'does not remove the BOM from a UTF16BE buffer' , function ( done ) {
85
117
var filepath = path . join ( __dirname , './fixtures/bom-utf16be.txt' ) ;
86
118
87
119
var expected = fs . readFileSync ( filepath ) ;
0 commit comments