Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"babel-preset-es2015": "6.18.0",
"babel-preset-react": "6.16.0",
"babel-runtime": "6.20.0",
"case-sensitive-paths-webpack-plugin": "1.1.4",
"cross-spawn": "5.0.1",
"del": "2.2.2",
"friendly-errors-webpack-plugin": "1.1.2",
Expand Down
4 changes: 3 additions & 1 deletion server/build/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import webpack from 'webpack'
import glob from 'glob-promise'
import WriteFilePlugin from 'write-file-webpack-plugin'
import FriendlyErrorsWebpackPlugin from 'friendly-errors-webpack-plugin'
import CaseSensitivePathPlugin from 'case-sensitive-paths-webpack-plugin'
import UnlinkFilePlugin from './plugins/unlink-file-plugin'
import WatchPagesPlugin from './plugins/watch-pages-plugin'
import WatchRemoveEventPlugin from './plugins/watch-remove-event-plugin'
Expand Down Expand Up @@ -71,7 +72,8 @@ export default async function createCompiler (dir, { dev = false, quiet = false
filename: 'commons.js',
minChunks: Math.max(2, minChunks)
}),
new JsonPagesPlugin()
new JsonPagesPlugin(),
new CaseSensitivePathPlugin()
]

if (dev) {
Expand Down
31 changes: 30 additions & 1 deletion server/resolve.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { join, sep } from 'path'
import { join, sep, parse } from 'path'
import fs from 'mz/fs'
import glob from 'glob-promise'

export default async function resolve (id) {
const paths = getPaths(id)
Expand Down Expand Up @@ -51,5 +52,33 @@ async function isFile (p) {
if (err.code === 'ENOENT') return false
throw err
}

// We need the path to be case sensitive
const realpath = await getTrueFilePath(p)
if (p !== realpath) return false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could warn during development here right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, this is in a utility library and passing dev option need to change in few places. And those changes seems to be looks nice. If we are using NODE_ENV then it would have been simple.

Here even in development, when clicked on link with an incorrect case, user will get a 404. I think that's a good way to show the problem.


return stat.isFile() || stat.isFIFO()
}

// This is based on the stackoverflow answer: http://stackoverflow.com/a/33139702/457224
// We assume we'll get properly normalized path names as p
async function getTrueFilePath (p) {
let fsPathNormalized = p
// OSX: HFS+ stores filenames in NFD (decomposed normal form) Unicode format,
// so we must ensure that the input path is in that format first.
if (process.platform === 'darwin') fsPathNormalized = fsPathNormalized.normalize('NFD')

// !! Windows: Curiously, the drive component mustn't be part of a glob,
// !! otherwise glob.sync() will invariably match nothing.
// !! Thus, we remove the drive component and instead pass it in as the 'cwd'
// !! (working dir.) property below.
var pathRoot = parse(fsPathNormalized).root
var noDrivePath = fsPathNormalized.slice(Math.max(pathRoot.length - 1, 0))

// Perform case-insensitive globbing (on Windows, relative to the drive /
// network share) and return the 1st match, if any.
// Fortunately, glob() with nocase case-corrects the input even if it is
// a *literal* path.
const result = await glob(noDrivePath, { nocase: true, cwd: pathRoot })
return result[0]
}
Loading