You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# %2F (/) and %5C (\) are NOT decoded, preventing them from creating
170
+
# additional path components in the file system
171
+
```
172
+
152
173
## Working with References
153
174
154
175
{ruby Protocol::URL::Reference} extends relative URLs with query parameters and fragments. For detailed information on working with references, see the [Working with References](../working-with-references/) guide.
Copy file name to clipboardExpand all lines: guides/working-with-references/readme.md
+75-12Lines changed: 75 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,21 @@ This guide explains how to use {ruby Protocol::URL::Reference} for managing URLs
10
10
11
11
You can create references in several ways:
12
12
13
-
### Constructing from Components
13
+
### Parsing External URLs (Untrusted Data)
14
+
15
+
Use {ruby Protocol::URL.parse} or {ruby Protocol::URL.[]} to parse URL strings from external sources (user input, APIs, web pages). These methods validate and decode the input:
# Don't decode forward slash (0x2F) or backslash (0x5C)
66
+
ifbyte == 0x2F || byte == 0x5C
67
+
hex# Keep as %2F or %5C
68
+
else
69
+
char
70
+
end
71
+
end.force_encoding(encoding)
72
+
end
73
+
30
74
# Matches characters that are not allowed in a URI path segment. According to RFC 3986 Section 3.3 (https://tools.ietf.org/html/rfc3986#section-3.3), a valid path segment consists of "pchar" characters. This pattern identifies characters that must be percent-encoded when included in a URI path segment.
# This method handles building nested data structures from query string parameters, including arrays of objects. When processing array elements (empty key like `[]`), it intelligently decides whether to add to the last array element or create a new one.
165
+
#
108
166
# @parameter keys [Array(String)] The parts of the key.
# Check if we should reuse the last array element or create a new one. If there's a nested key coming next, and the last array element already has that key, then we need a new array element. Otherwise, add to the existing one.
119
184
ifnested=middle[index+1]andlast=parent.last
185
+
# If the last element doesn't include the nested key, reuse it (decrement index).
186
+
# If it does include the key, keep current index (creates new element).
0 commit comments