|
| 1 | +## How to parse a `purl` string into its components |
| 2 | + |
| 3 | +Parsing a `purl` ASCII string into its components works from right to left, |
| 4 | +from `subpath` to `type`. |
| 5 | + |
| 6 | +Note: some extra type-specific normalizations are required. |
| 7 | +See the "Registered types section" for details. |
| 8 | + |
| 9 | +To parse a `purl` string in its components: |
| 10 | + |
| 11 | +- Split the `purl` string once from right on '#' |
| 12 | + |
| 13 | + - The left side is the `remainder` |
| 14 | + - Strip the right side from leading and trailing '/' |
| 15 | + - Split this on '/' |
| 16 | + - Discard any empty string segment from that split |
| 17 | + - Percent-decode each segment |
| 18 | + - Discard any '.' or '..' segment from that split |
| 19 | + - UTF-8-decode each segment if needed in your programming language |
| 20 | + - Join segments back with a '/' |
| 21 | + - This is the `subpath` |
| 22 | + |
| 23 | +- Split the `remainder` once from right on '?' |
| 24 | + |
| 25 | + - The left side is the `remainder` |
| 26 | + - The right side is the `qualifiers` string |
| 27 | + - Split the `qualifiers` on '&'. Each part is a `key=value` pair |
| 28 | + - For each pair, split the `key=value` once from left on '=': |
| 29 | + |
| 30 | + - The `key` is the lowercase left side |
| 31 | + - The `value` is the percent-decoded right side |
| 32 | + - UTF-8-decode the `value` if needed in your programming language |
| 33 | + - Discard any key/value pairs where the value is empty |
| 34 | + - If the `key` is `checksum`, split the `value` on ',' to create |
| 35 | + a list of checksums |
| 36 | + |
| 37 | + - This list of key/value is the `qualifiers` object |
| 38 | + |
| 39 | +- Split the `remainder` once from left on ':' |
| 40 | + |
| 41 | + - The left side lowercased is the `scheme` |
| 42 | + - The right side is the `remainder` |
| 43 | + |
| 44 | +- Strip all leading and trailing '/' characters (e.g., '/', '//', '///' and |
| 45 | + so on) from the `remainder` |
| 46 | + |
| 47 | + - Split this once from left on '/' |
| 48 | + - The left side lowercased is the `type` |
| 49 | + - The right side is the `remainder` |
| 50 | + |
| 51 | +- Split the `remainder` once from right on '@' |
| 52 | + |
| 53 | + - The left side is the `remainder` |
| 54 | + - Percent-decode the right side. This is the `version`. |
| 55 | + - UTF-8-decode the `version` if needed in your programming language |
| 56 | + - This is the `version` |
| 57 | + |
| 58 | +- Split the `remainder` once from right on '/' |
| 59 | + |
| 60 | + - The left side is the `remainder` |
| 61 | + - Strip all leading characters (e.g., '/', '//' and so on) |
| 62 | + from the right side |
| 63 | + - Percent-decode the right side. This is the `name` |
| 64 | + - UTF-8-decode this `name` if needed in your programming language |
| 65 | + - Apply type-specific normalization to the `name` if needed |
| 66 | + - This is the `name` |
| 67 | + |
| 68 | +- Split the `remainder` on '/' |
| 69 | + |
| 70 | + - Strip all leading '/' characters (e.g., '/', '//' and so on) |
| 71 | + from that split |
| 72 | + - Discard any empty segment from that split |
| 73 | + - Percent-decode each segment |
| 74 | + - UTF-8-decode each segment if needed in your programming language |
| 75 | + - Apply type-specific normalization to each segment if needed |
| 76 | + - Join segments back with a '/' |
| 77 | + - This is the `namespace` |
0 commit comments