|
10 | 10 | using System.Net.Http; |
11 | 11 | using System.Runtime.InteropServices; |
12 | 12 | using System.Text; |
| 13 | +using System.Text.Encodings.Web; |
13 | 14 | using System.Text.RegularExpressions; |
14 | 15 | using System.Threading; |
15 | 16 | using System.Threading.Tasks; |
@@ -1106,24 +1107,25 @@ public async void FileWatching_RespectsGracefulShutdownOptionWhenItsTrue() |
1106 | 1107 | // Arrange |
1107 | 1108 | Uri tempWatchDirectoryUri = CreateWatchDirectoryUri(); |
1108 | 1109 | // Create initial module |
1109 | | - string dummylongRunningTriggerPath = new Uri(tempWatchDirectoryUri, "dummyTriggerFile").AbsolutePath; // fs.watch can't deal with backslashes in paths |
| 1110 | + string dummylongRunningTriggerPath = new Uri(tempWatchDirectoryUri, "dummyTriggerFile").LocalPath; // Use LocalPath instead of AbsolutePath, the latter performs URL encoding, which results in paths that are invalid for local use |
1110 | 1111 | #if NET461 |
1111 | 1112 | File.WriteAllText(dummylongRunningTriggerPath, string.Empty); // fs.watch returns immediately if path to watch doesn't exist |
1112 | 1113 | #else |
1113 | 1114 | await File.WriteAllTextAsync(dummylongRunningTriggerPath, string.Empty).ConfigureAwait(false); // fs.watch returns immediately if path to watch doesn't exist |
1114 | 1115 | #endif |
| 1116 | + // JavascriptEncode.Default.Encode encodes a string so that it can be used as a string literal in Javascript |
1115 | 1117 | string dummyInitialModule = $@"module.exports = {{ |
1116 | 1118 | getPid: (callback) => callback(null, process.pid), |
1117 | 1119 | longRunning: (callback) => {{ |
1118 | | - fs.watch('{dummylongRunningTriggerPath}', |
| 1120 | + fs.watch('{JavaScriptEncoder.Default.Encode(dummylongRunningTriggerPath)}', |
1119 | 1121 | null, |
1120 | 1122 | () => {{ |
1121 | 1123 | callback(null, process.pid); |
1122 | 1124 | }} |
1123 | 1125 | ); |
1124 | 1126 | }} |
1125 | 1127 | }}"; |
1126 | | - string dummyModuleFilePath = new Uri(tempWatchDirectoryUri, "dummyModule.js").AbsolutePath; |
| 1128 | + string dummyModuleFilePath = new Uri(tempWatchDirectoryUri, "dummyModule.js").LocalPath; |
1127 | 1129 | #if NET461 |
1128 | 1130 | File.WriteAllText(dummyModuleFilePath, dummyInitialModule); |
1129 | 1131 | #else |
@@ -1175,7 +1177,7 @@ public async void FileWatching_RespectsGracefulShutdownOptionWhenItsFalse() |
1175 | 1177 | getPid: (callback) => callback(null, process.pid), |
1176 | 1178 | longRunning: (callback) => setInterval(() => { /* Do nothing */ }, 1000) |
1177 | 1179 | }"; |
1178 | | - string dummyModuleFilePath = new Uri(CreateWatchDirectoryUri(), "dummyModule.js").AbsolutePath; |
| 1180 | + string dummyModuleFilePath = new Uri(CreateWatchDirectoryUri(), "dummyModule.js").LocalPath; |
1179 | 1181 | #if NET461 |
1180 | 1182 | File.WriteAllText(dummyModuleFilePath, dummyInitialModule); |
1181 | 1183 | #else |
|
0 commit comments