-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Now BOM is preserved for UTF-8 files #13477
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,13 @@ define(function (require, exports, module) { | |
*/ | ||
File.prototype._encoding = null; | ||
|
||
/** | ||
* BOM detected by brackets-shell | ||
* @private | ||
* @type {?bool} | ||
*/ | ||
File.prototype._preserveBOM = false; | ||
|
||
/** | ||
* Consistency hash for this file. Reads and writes update this value, and | ||
* writes confirm the hash before overwriting existing files. The type of | ||
|
@@ -103,7 +110,7 @@ define(function (require, exports, module) { | |
// for a default value; otherwise it could be the empty string, which is | ||
// falsey. | ||
if (this._contents !== null && this._stat) { | ||
callback(null, this._contents, this._encoding, this._stat); | ||
callback(null, this._contents, this._encoding, this._preserveBOM, this._stat); | ||
return; | ||
} | ||
|
||
|
@@ -112,7 +119,7 @@ define(function (require, exports, module) { | |
options.stat = this._stat; | ||
} | ||
|
||
this._impl.readFile(this._path, options, function (err, data, encoding, stat) { | ||
this._impl.readFile(this._path, options, function (err, data, encoding, preserveBOM, stat) { | ||
if (err) { | ||
this._clearCachedData(); | ||
callback(err); | ||
|
@@ -122,14 +129,15 @@ define(function (require, exports, module) { | |
// Always store the hash | ||
this._hash = stat._hash; | ||
this._encoding = encoding; | ||
this._preserveBOM = preserveBOM; | ||
|
||
// Only cache data for watched files | ||
if (watched) { | ||
this._stat = stat; | ||
this._contents = data; | ||
} | ||
|
||
callback(err, data, encoding, stat); | ||
callback(err, data, encoding, this._preserveBOM, stat); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the preserveBOM marker from callback. It should be consumed internally and kept in File prototype only. |
||
}.bind(this)); | ||
}; | ||
|
||
|
@@ -159,6 +167,7 @@ define(function (require, exports, module) { | |
options.expectedContents = this._contents; | ||
} | ||
options.encoding = this._encoding || "utf8"; | ||
options.preserveBOM = this._preserveBOM; | ||
|
||
// Block external change events until after the write has finished | ||
this._fileSystem._beginChange(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -363,11 +363,11 @@ define(function (require, exports, module) { | |
if (stat.size > (FileUtils.MAX_FILE_SIZE)) { | ||
callback(FileSystemError.EXCEEDS_MAX_FILE_SIZE); | ||
} else { | ||
appshell.fs.readFile(path, encoding, function (_err, _data, encoding) { | ||
appshell.fs.readFile(path, encoding, function (_err, _data, encoding, preserveBOM) { | ||
if (_err) { | ||
callback(_mapError(_err)); | ||
} else { | ||
callback(null, _data, encoding, stat); | ||
callback(null, _data, encoding, preserveBOM, stat); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the preserveBOM marker from callback. It should be consumed internally and kept in File prototype only. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My bad. You do need it . |
||
} | ||
}); | ||
} | ||
|
@@ -403,10 +403,11 @@ define(function (require, exports, module) { | |
* @param {function(?string, FileSystemStats=, boolean)} callback | ||
*/ | ||
function writeFile(path, data, options, callback) { | ||
var encoding = options.encoding || "utf8"; | ||
var encoding = options.encoding || "utf8", | ||
preserveBOM = options.preserveBOM; | ||
|
||
function _finishWrite(created) { | ||
appshell.fs.writeFile(path, data, encoding, function (err) { | ||
appshell.fs.writeFile(path, data, encoding, preserveBOM, function (err) { | ||
if (err) { | ||
callback(_mapError(err)); | ||
} else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,10 +56,11 @@ define(function (require, exports, module) { | |
} | ||
|
||
function readCallback() { | ||
var callback = function (err, data, encoding, stat) { | ||
var callback = function (err, data, encoding, preserveBOM, stat) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test shouldn't be modified. The BOM flag is purely an internal config option and shouldn't be exposed. In case we want to expose this in future, it has to be a preference and that too only for write part. |
||
callback.error = err; | ||
callback.data = data; | ||
callback.encoding = "utf8"; | ||
callback.preserveBOM = false; | ||
callback.stat = stat; | ||
callback.wasCalled = true; | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,7 +141,7 @@ define(function (require, exports, module) { | |
if (!_model.exists(path)) { | ||
cb(FileSystemError.NOT_FOUND); | ||
} else { | ||
cb(null, _model.readFile(path), "UTF-8", _model.stat(path)); | ||
cb(null, _model.readFile(path), "UTF-8", false, _model.stat(path)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as before. |
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the preserveBOM marker from callback. It should be consumed internally and kept in File prototype only.