Skip to content

Commit 80d5ed3

Browse files
authored
Merge pull request #1555 from BrowserSync/bugs/1553
fix: handle windows-style paths on the client - fixes #1553
2 parents 3073d61 + 1153845 commit 80d5ed3

3 files changed

Lines changed: 25 additions & 4 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ bs-config.js
2020
/lodash.custom.min.js
2121
/dist
2222
/cypress/videos
23+
/cypress/screenshots/*
2324
client/dist/index.js
2425
client/dist/index.js.map
2526
client/dist/index.min.js
26-
client/dist/index.min.js.map
27+
client/dist/index.min.js.map

client/lib/utils.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ export const pickBestMatch = function(path, objects, pathFunc): any {
6161
};
6262

6363
export const numberOfMatchingSegments = function(path1, path2) {
64-
// get rid of leading slashes and normalize to lower case
65-
path1 = path1.replace(/^\/+/, "").toLowerCase();
66-
path2 = path2.replace(/^\/+/, "").toLowerCase();
64+
path1 = normalisePath(path1);
65+
path2 = normalisePath(path2);
6766

6867
if (path1 === path2) {
6968
return 10000;
@@ -153,3 +152,10 @@ export function createTimedBooleanSwitch(source$, timeout = 1000) {
153152
export function array(incoming) {
154153
return [].slice.call(incoming);
155154
}
155+
156+
export function normalisePath(path: string): string {
157+
return path
158+
.replace(/^\/+/, "")
159+
.replace(/\\/g, "/")
160+
.toLowerCase();
161+
}

cypress/integration/file-reloading.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ describe('Reloading files', function() {
3434
});
3535
});
3636
});
37+
it('should reload with windows style paths', function() {
38+
cy.get('#__bs_notify__').should('have.length', 1);
39+
cy.request('POST', 'http://localhost:3000/__browser_sync__',
40+
JSON.stringify([
41+
"file:reload",
42+
{"ext":"css","path":"C:\\#server\\test\\gulp-test\\assets\\style.css","basename":"style.css","event":"change","type":"inject","log":false}
43+
])
44+
);
45+
cy.get('[id="css-style"]').should('have.length', 1);
46+
cy.get('[id="css-style"]').eq(0).should((link) => {
47+
const url = new URL(link[0].href);
48+
return expect(url.search).to.contain('?browsersync=');
49+
})
50+
});
3751
});
3852
context('CSS IMPORTS', function() {
3953
it('can import 1 stylesheet from <style>@import</style>', () => {

0 commit comments

Comments
 (0)