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