@@ -16,7 +16,7 @@ suite('StackTraceHelper', () => {
16
16
'@Main c:\\src\\test\\3\\otherlanguages\\julia.ipynb: 3\n' +
17
17
'[2] top - level scope\n' +
18
18
'@c:\\src\\test\\3\\otherlanguages\\julia.ipynb: 1; ' ;
19
- assert . equal ( formatStackTrace ( stack ) . formattedStack , stack ) ;
19
+ assert . equal ( formatStackTrace ( stack , true ) . formattedStack , stack ) ;
20
20
} ) ;
21
21
22
22
const formatSequence = / \u001b \[ .+ ?m / g;
@@ -37,7 +37,7 @@ suite('StackTraceHelper', () => {
37
37
'\u001b[1;32m----> 2\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m\n\n' +
38
38
'\u001b[1;31mException\u001b[0m\n:' ;
39
39
40
- const { formattedStack, errorLocation } = formatStackTrace ( stack ) ;
40
+ const { formattedStack, errorLocation } = formatStackTrace ( stack , true ) ;
41
41
const cleanStack = stripAsciiFormatting ( formattedStack ) ;
42
42
assert . ok ( cleanStack . indexOf ( 'Cell In[3], <a href=\'vscode-notebook-cell:?execution_count=3&line=2\'>line 2</a>' ) > 0 , 'Missing line link in ' + cleanStack ) ;
43
43
assert . ok ( cleanStack . indexOf ( '<a href=\'vscode-notebook-cell:?execution_count=3&line=2\'>2</a>' ) > 0 , 'Missing frame link in ' + cleanStack ) ;
@@ -56,13 +56,28 @@ suite('StackTraceHelper', () => {
56
56
'\n' +
57
57
'\u001b[31mTypeError\u001b[39m: unsupported operand type(s) for +: "NoneType" and "int"\n' ;
58
58
59
- const { formattedStack, errorLocation } = formatStackTrace ( stack ) ;
59
+ const { formattedStack, errorLocation } = formatStackTrace ( stack , true ) ;
60
60
const cleanStack = stripAsciiFormatting ( formattedStack ) ;
61
61
assert . ok ( cleanStack . indexOf ( 'Cell In[3], <a href=\'vscode-notebook-cell:?execution_count=3&line=2\'>line 2</a>' ) > 0 , 'Missing line link in ' + cleanStack ) ;
62
62
assert . ok ( cleanStack . indexOf ( '<a href=\'vscode-notebook-cell:?execution_count=3&line=2\'>2</a>' ) > 0 , 'Missing frame link in ' + cleanStack ) ;
63
63
assert . equal ( errorLocation , '<a href=\'vscode-notebook-cell:?execution_count=3&line=2\'>line 2</a>' ) ;
64
64
} ) ;
65
65
66
+ test ( 'Stack trace is not linkified when HTML is not trusted' , ( ) => {
67
+ const stack =
68
+ '\u001b[31m---------------------------------------------------------------------------\u001b[39m\n' +
69
+ '\u001b[31mTypeError\u001b[39m Traceback (most recent call last)\n' +
70
+ '\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[3]\u001b[39m\u001b[32m, line 2\u001b[39m\n' +
71
+ '\u001b[32m 1\u001b[39m x = firstItem((\u001b[32m1\u001b[39m, \u001b[32m2\u001b[39m, \u001b[32m3\u001b[39m, \u001b[32m5\u001b[39m))\n' +
72
+ '\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m y = \u001b[43mx\u001b[49m\u001b[43m \u001b[49m\u001b[43m+\u001b[49m\u001b[43m \u001b[49m\u001b[32;43m1\u001b[39;49m\n' +
73
+ '\u001b[32m 3\u001b[39m \u001b[38;5;28mprint\u001b[39m(y)\n' +
74
+ '\n' +
75
+ '\u001b[31mTypeError\u001b[39m: unsupported operand type(s) for +: "NoneType" and "int"\n' ;
76
+
77
+ const formattedLines = formatStackTrace ( stack , false ) . formattedStack . split ( '\n' ) ;
78
+ formattedLines . forEach ( line => assert . ok ( ! / < a h r e f = .* > / . test ( line ) , 'line should not contain a link: ' + line ) ) ;
79
+ } ) ;
80
+
66
81
test ( 'IPython stack line numbers are linkified for IPython 8.3' , ( ) => {
67
82
// stack frames within functions do not list the line number, i.e.
68
83
// 'Input In [1], in myfunc()' vs
@@ -85,7 +100,7 @@ suite('StackTraceHelper', () => {
85
100
'\n' +
86
101
'\u001b[1;31mException\u001b[0m:\n' ;
87
102
88
- const { formattedStack } = formatStackTrace ( stack ) ;
103
+ const { formattedStack } = formatStackTrace ( stack , true ) ;
89
104
const formatted = stripAsciiFormatting ( formattedStack ) ;
90
105
assert . ok ( formatted . indexOf ( 'Input <a href=\'vscode-notebook-cell:?execution_count=2\'>In [2]</a>, in <cell line: 5>' ) > 0 , 'Missing cell link in ' + formatted ) ;
91
106
assert . ok ( formatted . indexOf ( 'Input <a href=\'vscode-notebook-cell:?execution_count=1\'>In [1]</a>, in myfunc()' ) > 0 , 'Missing cell link in ' + formatted ) ;
@@ -103,7 +118,7 @@ suite('StackTraceHelper', () => {
103
118
'\u001b[1;32m----> 2\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m\n\n' +
104
119
'\u001b[1;31mException\u001b[0m\n:' ;
105
120
106
- const formatted = formatStackTrace ( stack ) . formattedStack ;
121
+ const formatted = formatStackTrace ( stack , true ) . formattedStack ;
107
122
assert . ok ( ! / < a h r e f = .* > \d < \/ a > / . test ( formatted ) , formatted ) ;
108
123
} ) ;
109
124
@@ -118,7 +133,7 @@ suite('StackTraceHelper', () => {
118
133
'a 1 print(\n' +
119
134
' 1a print(\n' ;
120
135
121
- const formattedLines = formatStackTrace ( stack ) . formattedStack . split ( '\n' ) ;
136
+ const formattedLines = formatStackTrace ( stack , true ) . formattedStack . split ( '\n' ) ;
122
137
assert . ok ( / < a h r e f = ' v s c o d e - n o t e b o o k - c e l l .* > / . test ( formattedLines [ 0 ] ) , 'line should contain a link: ' + formattedLines [ 0 ] ) ;
123
138
formattedLines . slice ( 1 ) . forEach ( line => assert . ok ( ! / < a h r e f = .* > / . test ( line ) , 'line should not contain a link: ' + line ) ) ;
124
139
} ) ;
@@ -127,7 +142,7 @@ suite('StackTraceHelper', () => {
127
142
const stack =
128
143
'open\u001b[39;49m\u001b[43m(\u001b[49m\u001b[33;43m\'\u001b[39;49m\u001b[33;43minput.txt\u001b[39;49m\u001b[33;43m\'\u001b[39;49m\u001b[43m)\u001b[49m;' ;
129
144
130
- const formattedLines = formatStackTrace ( stack ) . formattedStack . split ( '\n' ) ;
145
+ const formattedLines = formatStackTrace ( stack , true ) . formattedStack . split ( '\n' ) ;
131
146
assert . ok ( ! / 4 \d / . test ( formattedLines [ 0 ] ) , 'should not contain background colors ' + formattedLines [ 0 ] ) ;
132
147
formattedLines . slice ( 1 ) . forEach ( line => assert . ok ( ! / < a h r e f = .* > / . test ( line ) , 'line should not contain a link: ' + line ) ) ;
133
148
} ) ;
0 commit comments