File tree Expand file tree Collapse file tree
main/java/com/github/_1c_syntax/utils
test/java/com/github/_1c_syntax/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ public final class Absolute {
4848 */
4949 public static URI uri (@ NonNull String uri ) {
5050 try {
51- var url = new URL (uri );
51+ var url = new URL (uri . replace ( "+" , "%2B" ) );
5252 var decodedPath = URLDecoder .decode (url .getPath (), StandardCharsets .UTF_8 );
5353 var decodedUri = new URI (
5454 url .getProtocol (),
@@ -133,6 +133,8 @@ private static String encodePath(@NonNull String path) {
133133 return path
134134 .replace (" " , "%20" )
135135 .replace ("#" , "%23" )
136+ .replace ("+" , "%2B" )
137+ .replace ("," , "%2C" )
136138 .replace ("[" , "%91" )
137139 .replace ("]" , "%93" )
138140 .replace ("?" , "%3F" )
@@ -141,6 +143,7 @@ private static String encodePath(@NonNull String path) {
141143 .replace (":" , "%3A" )
142144 .replace ("\" " , "%22" )
143145 .replace ("\\ " , "%5C" )
146+ .replace ("^" , "%5E" )
144147 ;
145148 }
146149
Original file line number Diff line number Diff line change @@ -79,6 +79,55 @@ void testUNCURI() {
7979 ;
8080 }
8181
82+ @ Test
83+ void testStringWithPlus () {
84+ // given
85+ var uriString = "file:///git/some+thing.os" ;
86+
87+ // when
88+ var uri = Absolute .uri (uriString );
89+
90+ // then
91+ assertThat (uri )
92+ .hasScheme ("file" );
93+
94+ assertThat (uri .getPath ())
95+ .endsWith ("some+thing.os" );
96+ }
97+
98+ @ Test
99+ void testEscapedSymbols () {
100+ // given
101+ var uriString = "file:///git/1_Тест-Набор.Со+Странным^Именем_1,.os" ;
102+
103+ // when
104+ var uri = Absolute .uri (uriString );
105+
106+ // then
107+ assertThat (uri )
108+ .hasScheme ("file" );
109+
110+ assertThat (uri .getPath ())
111+ .endsWith ("1_Тест-Набор.Со+Странным^Именем_1,.os" );
112+ }
113+
114+ @ Test
115+ void testEscapedSymbolsURI () {
116+ // given
117+ var file = new File ("/git/1_Тест-Набор.Со+Странным^Именем_1,.os" );
118+ var uriFromFile = file .toURI ();
119+
120+ // when
121+ var uri = Absolute .uri (uriFromFile );
122+
123+ // then
124+ assertThat (uri )
125+ .hasScheme ("file" );
126+
127+ assertThat (uri .getPath ())
128+ .endsWith ("1_Тест-Набор.Со+Странным^Именем_1,.os" );
129+ }
130+
82131 @ Test
83132 void testUNCWithPortURI () {
84133 // given
You can’t perform that action at this time.
0 commit comments