@@ -140,54 +140,51 @@ static URI_INLINE int URI_FUNC(UriStringToFilename)(const URI_CHAR * uriString,
140140 return URI_ERROR_NULL ;
141141 }
142142
143- const UriBool file_unknown_slashes =
144- URI_STRNCMP (uriString , _UT ("file:" ), URI_STRLEN (_UT ("file:" ))) == 0 ;
145- const UriBool file_one_or_more_slashes =
146- file_unknown_slashes
147- && (URI_STRNCMP (uriString , _UT ("file:/" ), URI_STRLEN (_UT ("file:/" ))) == 0 );
148- const UriBool file_two_or_more_slashes =
149- file_one_or_more_slashes
150- && (URI_STRNCMP (uriString , _UT ("file://" ), URI_STRLEN (_UT ("file://" ))) == 0 );
151- const UriBool file_three_or_more_slashes =
152- file_two_or_more_slashes
153- && (URI_STRNCMP (uriString , _UT ("file:///" ), URI_STRLEN (_UT ("file:///" )))
154- == 0 );
155-
156- const size_t charsToSkip =
157- file_two_or_more_slashes
158- ? file_three_or_more_slashes
159- ? toUnix
160- /* file:///bin/bash */
161- ? URI_STRLEN (_UT ("file://" ))
162- /* file:///E:/Documents%20and%20Settings */
163- : URI_STRLEN (_UT ("file:///" ))
164- /* file://Server01/Letter.txt */
165- : URI_STRLEN (_UT ("file://" ))
166- : ((file_one_or_more_slashes && toUnix )
167- /* file:/bin/bash */
168- /* https://tools.ietf.org/html/rfc8089#appendix-B */
169- ? URI_STRLEN (_UT ("file:" ))
170- : ((!toUnix && file_unknown_slashes && !file_one_or_more_slashes )
171- /* file:c:/path/to/file */
172- /* https://tools.ietf.org/html/rfc8089#appendix-E.2 */
173- ? URI_STRLEN (_UT ("file:" ))
174- : 0 ));
175- const size_t charsToCopy = URI_STRLEN (uriString + charsToSkip ) + 1 ;
176-
177- const UriBool is_windows_network_with_authority = (toUnix == URI_FALSE )
178- && file_two_or_more_slashes
179- && !file_three_or_more_slashes ;
180-
181- URI_CHAR * const unescape_target =
182- is_windows_network_with_authority ? (filename + 2 ) : filename ;
183-
184- if (is_windows_network_with_authority ) {
185- filename [0 ] = '\\' ;
186- filename [1 ] = '\\' ;
187- }
143+ const UriBool file_unknown_slashes =
144+ URI_STRNCMP (uriString , _UT ("file:" ), URI_STRLEN (_UT ("file:" ))) == 0 ;
145+ const UriBool file_one_or_more_slashes =
146+ file_unknown_slashes
147+ && (URI_STRNCMP (uriString , _UT ("file:/" ), URI_STRLEN (_UT ("file:/" ))) == 0 );
148+ const UriBool file_two_or_more_slashes =
149+ file_one_or_more_slashes
150+ && (URI_STRNCMP (uriString , _UT ("file://" ), URI_STRLEN (_UT ("file://" ))) == 0 );
151+ const UriBool file_three_or_more_slashes =
152+ file_two_or_more_slashes
153+ && (URI_STRNCMP (uriString , _UT ("file:///" ), URI_STRLEN (_UT ("file:///" ))) == 0 );
154+
155+ const size_t charsToSkip =
156+ file_two_or_more_slashes
157+ ? file_three_or_more_slashes ? toUnix
158+ /* file:///bin/bash */
159+ ? URI_STRLEN (_UT ("file://" ))
160+ /* file:///E:/Documents%20and%20Settings */
161+ : URI_STRLEN (_UT ("file:///" ))
162+ /* file://Server01/Letter.txt */
163+ : URI_STRLEN (_UT ("file://" ))
164+ : ((file_one_or_more_slashes && toUnix )
165+ /* file:/bin/bash */
166+ /* https://tools.ietf.org/html/rfc8089#appendix-B */
167+ ? URI_STRLEN (_UT ("file:" ))
168+ : ((!toUnix && file_unknown_slashes && !file_one_or_more_slashes )
169+ /* file:c:/path/to/file */
170+ /* https://tools.ietf.org/html/rfc8089#appendix-E.2 */
171+ ? URI_STRLEN (_UT ("file:" ))
172+ : 0 ));
173+ const size_t charsToCopy = URI_STRLEN (uriString + charsToSkip ) + 1 ;
174+
175+ const UriBool is_windows_network_with_authority =
176+ (toUnix == URI_FALSE ) && file_two_or_more_slashes && !file_three_or_more_slashes ;
177+
178+ URI_CHAR * const unescape_target =
179+ is_windows_network_with_authority ? (filename + 2 ) : filename ;
180+
181+ if (is_windows_network_with_authority ) {
182+ filename [0 ] = '\\' ;
183+ filename [1 ] = '\\' ;
184+ }
188185
189- memcpy (unescape_target , uriString + charsToSkip , charsToCopy * sizeof (URI_CHAR ));
190- URI_FUNC (UnescapeInPlaceEx )(filename , URI_FALSE , URI_BR_DONT_TOUCH );
186+ memcpy (unescape_target , uriString + charsToSkip , charsToCopy * sizeof (URI_CHAR ));
187+ URI_FUNC (UnescapeInPlaceEx )(filename , URI_FALSE , URI_BR_DONT_TOUCH );
191188
192189 /* Convert forward slashes to backslashes */
193190 if (!toUnix ) {
0 commit comments