(Object str2)
| 387 | // } |
| 388 | |
| 389 | public static String encodeURIComponent(Object str2) { |
| 390 | String str = (String) str2; |
| 391 | // Match JS encodeURIComponent: unreserved set is A-Z a-z 0-9 - _ . ~ ! * ' ( ) |
| 392 | // Brackets `[` `]` ARE encoded. (The previous version included them in |
| 393 | // the unreserved set to mimic C# HttpUtility output, but TS sources |
| 394 | // call encodeURIComponent expecting JS semantics — e.g. aster.cancelOrders |
| 395 | // produces `orderIdList=%5B...%5D`.) |
| 396 | String unreserved = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~!*'()"; |
| 397 | |
| 398 | StringBuilder result = new StringBuilder(str.length() * 3); |
| 399 | |
| 400 | byte[] bytes = str.getBytes(StandardCharsets.UTF_8); |
| 401 | for (byte b : bytes) { |
| 402 | int c = b & 0xFF; |
| 403 | char ch = (char) c; |
| 404 | |
| 405 | if (unreserved.indexOf(ch) != -1) { |
| 406 | result.append(ch); |
| 407 | } else { |
| 408 | result.append('%'); |
| 409 | result.append(String.format("%02X", c)); |
| 410 | } |
| 411 | } |
| 412 | return result.toString(); |
| 413 | } |
| 414 | |
| 415 | private static String urlEncode(String s) { |
| 416 | try { |
no test coverage detected