@@ -57,6 +57,13 @@ const {
5757 O_SYMLINK ,
5858} = constants ;
5959
60+ function isUtf8Encoding ( encoding ) {
61+ return encoding === 'utf8' ||
62+ encoding === 'utf-8' ||
63+ encoding === 'UTF8' ||
64+ encoding === 'UTF-8' ;
65+ }
66+
6067const pathModule = require ( 'path' ) ;
6168const { isArrayBufferView } = require ( 'internal/util/types' ) ;
6269
@@ -611,13 +618,18 @@ function readFileSync(path, options) {
611618 validateReadFileBufferOptions ( options ) ;
612619 const hasUserBuffer = options . buffer !== undefined ;
613620
621+ < << << << HEAD
614622 if ( ( options . encoding === 'utf8' || options . encoding === 'utf-8' ) &&
615623 ! hasUserBuffer ) {
616624 if ( isInt32 ( path ) ) {
617625 // V8 does not report -0 as an int32, so it would reach the binding as a
618626 // path instead of a file descriptor.
619627 path |= 0 ;
620628 } else {
629+ === === =
630+ if ( isUtf8Encoding ( options . encoding ) && ! hasUserBuffer ) {
631+ if ( ! isInt32 ( path ) ) {
632+ >>> >>> > fccaa919c21 ( fs : accept all valid utf8 values in fast paths )
621633 path = getValidatedPath ( path ) ;
622634 }
623635 return binding . readFileUtf8 ( path , stringToFlags ( options . flag ) ) ;
@@ -3015,12 +3027,17 @@ function writeFileSync(path, data, options) {
30153027 const flag = options . flag || 'w' ;
30163028
30173029 // C++ fast path for string data and UTF8 encoding
3030+ < << << << HEAD
30183031 if ( typeof data === 'string' && ( options . encoding === 'utf8' || options . encoding === 'utf-8' ) ) {
30193032 if ( isInt32 ( path ) ) {
30203033 // V8 does not report -0 as an int32, so it would reach the binding as a
30213034 // path instead of a file descriptor.
30223035 path |= 0 ;
30233036 } else {
3037+ === === =
3038+ if ( typeof data === 'string' && isUtf8Encoding ( options . encoding ) ) {
3039+ if ( ! isInt32 ( path ) ) {
3040+ >>> >>> > fccaa919c21 ( fs : accept all valid utf8 values in fast paths )
30243041 path = getValidatedPath ( path ) ;
30253042 }
30263043
@@ -3320,7 +3337,7 @@ if (isWindows) {
33203337}
33213338
33223339function encodeRealpathResult ( result , options ) {
3323- if ( ! options || ! options . encoding || options . encoding === 'utf8' )
3340+ if ( ! options || ! options . encoding || isUtf8Encoding ( options . encoding ) )
33243341 return result ;
33253342 const asBuffer = Buffer . from ( result ) ;
33263343 if ( options . encoding === 'buffer' ) {
0 commit comments