@@ -25,31 +25,56 @@ describe('message-stream', () => {
25
25
} )
26
26
} )
27
27
28
- function getOutputFromStream ( inputLines ) {
28
+ function getOutputFromStream ( inputLines , pipeOpts ) {
29
29
return new Promise ( ( resolve ) => {
30
30
const ms = new MessageStream ( { main : { } } , 'msg' , [ ] )
31
31
const output = new stream . PassThrough ( )
32
32
const chunks = [ ]
33
33
34
- output . on ( 'data' , chunk => chunks . push ( chunk . toString ( ) ) )
34
+ output . on ( 'data' , ( chunk ) => chunks . push ( chunk . toString ( ) ) )
35
35
output . on ( 'end' , ( ) => resolve ( chunks . join ( '' ) ) )
36
36
37
- ms . pipe ( output , { dot_stuffed : true } )
37
+ ms . pipe ( output , pipeOpts )
38
38
39
- inputLines . forEach ( line => ms . add_line ( line ) )
39
+ inputLines . forEach ( ( line ) => ms . add_line ( line ) )
40
40
ms . add_line_end ( )
41
41
} )
42
42
}
43
43
44
- describe ( 'dot-unstuffing' , function ( ) {
44
+ describe ( 'dot_stuffed = false' , function ( ) {
45
+ const pipeOpts = { dot_stuffed : false }
46
+
47
+ it ( 'does not stuff "..\\r\\n' , async ( ) => {
48
+ const result = await getOutputFromStream ( [ '..\r\n' ] , pipeOpts )
49
+ assert . match ( result , / ^ ..\r \n / m)
50
+ } )
51
+
52
+ it ( 'does not stuff "..dot start\\r\\n"' , async ( ) => {
53
+ const result = await getOutputFromStream ( [ '..dot start\r\n' ] , pipeOpts )
54
+ assert . match ( result , / ^ ..d o t s t a r t \r \n / m)
55
+ } )
56
+
57
+ it ( 'leaves normal lines untouched' , async ( ) => {
58
+ const result = await getOutputFromStream ( [
59
+ 'hello\r\n' ,
60
+ '..dot line\r\n' ,
61
+ '..\r\n' ,
62
+ ] , pipeOpts )
63
+
64
+ assert . equal ( result , 'hello\r\n..dot line\r\n..\r\n' )
65
+ } )
66
+ } )
67
+
68
+ describe ( 'dot_stuffed = true' , function ( ) {
69
+ const pipeOpts = { dot_stuffed : true }
45
70
46
71
it ( 'unstuffs "..\\r\\n" to ".\\r\\n"' , async ( ) => {
47
- const result = await getOutputFromStream ( [ '..\r\n' ] )
72
+ const result = await getOutputFromStream ( [ '..\r\n' ] , pipeOpts )
48
73
assert . match ( result , / ^ .\r \n / m)
49
74
} )
50
75
51
76
it ( 'unstuffs "..dot start\\r\\n" to ".dot start\\r\\n"' , async ( ) => {
52
- const result = await getOutputFromStream ( [ '..dot start\r\n' ] )
77
+ const result = await getOutputFromStream ( [ '..dot start\r\n' ] , pipeOpts )
53
78
assert . match ( result , / ^ .d o t s t a r t \r \n / m)
54
79
} )
55
80
@@ -58,13 +83,36 @@ describe('dot-unstuffing', function () {
58
83
'hello\r\n' ,
59
84
'..dot line\r\n' ,
60
85
'..\r\n' ,
61
- ] )
86
+ ] , pipeOpts )
62
87
63
88
assert . equal ( result , 'hello\r\n.dot line\r\n.\r\n' )
64
89
assert . match ( result , / ^ h e l l o \r \n / m)
65
90
assert . match ( result , / ^ .d o t l i n e \r \n / m)
66
91
assert . match ( result , / ^ .\r \n / m)
67
92
} )
93
+ } )
68
94
95
+ describe ( 'dot_stuffing = false (legacy)' , function ( ) {
96
+ // sunset, delete after 2026
97
+ const pipeOpts = { dot_stuffing : false }
69
98
99
+ it ( 'unstuffs "..\\r\\n" to ".\\r\\n"' , async ( ) => {
100
+ const result = await getOutputFromStream ( [ '..\r\n' ] , pipeOpts )
101
+ assert . match ( result , / ^ .\r \n / m)
102
+ } )
103
+
104
+ it ( 'unstuffs "..dot start\\r\\n" to ".dot start\\r\\n"' , async ( ) => {
105
+ const result = await getOutputFromStream ( [ '..dot start\r\n' ] , pipeOpts )
106
+ assert . match ( result , / ^ .d o t s t a r t \r \n / m)
107
+ } )
108
+
109
+ it ( 'leaves normal lines untouched' , async ( ) => {
110
+ const result = await getOutputFromStream ( [
111
+ 'hello\r\n' ,
112
+ '..dot line\r\n' ,
113
+ '..\r\n' ,
114
+ ] , pipeOpts )
115
+
116
+ assert . equal ( result , 'hello\r\n.dot line\r\n.\r\n' )
117
+ } )
70
118
} )
0 commit comments