Skip to content

Commit e4c1574

Browse files
committed
Encoding
1 parent eb48c61 commit e4c1574

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

5-network/07-url/article.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,26 +114,26 @@ for(let [name, value] of url.searchParams) {
114114
```
115115

116116

117-
## Encoding
117+
## Кодування
118118

119-
There's a standard [RFC3986](https://tools.ietf.org/html/rfc3986) that defines which characters are allowed in URLs and which are not.
119+
Набір символів, що можуть дозволено до використання в URL-адресах, визначено в стандарті [RFC3986](https://tools.ietf.org/html/rfc3986).
120120

121-
Those that are not allowed, must be encoded, for instance non-latin letters and spaces - replaced with their UTF-8 codes, prefixed by `%`, such as `%20` (a space can be encoded by `+`, for historical reasons, but that's an exception).
121+
Усі інші символи, що не дозволені стандартом, повинні бути закодовані. Наприклад, не латинські букви та пробіл повинні бути заміненими на їх UTF-8 коди, що починаються з `%`. Пробіл буде закодовано у вигляді `%20` (з історичних причин пробіл дозволено закодувати як `+`).
122122

123-
The good news is that `URL` objects handle all that automatically. We just supply all parameters unencoded, and then convert the `URL` to string:
123+
Гарна новина полягає в тому, що `URL` об'єкт виконає всі перетворення автоматично. Нам потрібно тільки передати всі параметри, а потім перетворити `URL` в рядок:
124124

125125
```js run
126-
// using some cyrillic characters for this example
126+
// для прикладу використано кириличні символи
127127

128-
let url = new URL('https://ru.wikipedia.org/wiki/Тест');
128+
let url = new URL('https://uk.wikipedia.org/wiki/Тест');
129129

130-
url.searchParams.set('key', 'ъ');
131-
alert(url); //https://ru.wikipedia.org/wiki/%D0%A2%D0%B5%D1%81%D1%82?key=%D1%8A
130+
url.searchParams.set('key', 'ї');
131+
alert(url); // https://uk.wikipedia.org/wiki/%D0%A2%D0%B5%D1%81%D1%82?key=%D1%97
132132
```
133133

134-
As you can see, both `Тест` in the url path and `ъ` in the parameter are encoded.
134+
Як бачите, і `Тест` у шляху, і параметр `ї` закодовано.
135135

136-
The URL became longer, because each cyrillic letter is represented with two bytes in UTF-8, so there are two `%..` entities.
136+
URL-адреса стала довшою, бо кожен кириличний символ представлено двома байтами в UTF-8, тому там дві групи символів `%..`.
137137

138138
### Encoding strings
139139

0 commit comments

Comments
 (0)