Skip to content

Commit 35059f3

Browse files
committed
Changed term 'domain' to 'origin' for a more precise definition.
1 parent 8b07c7c commit 35059f3

File tree

8 files changed

+39
-39
lines changed

8 files changed

+39
-39
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
### Description
1818

1919
- [Parses](https://github.com/tomasfn87/url-parser/blob/main/index.html#L42) a URL in 4 parts:
20-
- `Domain`;
20+
- `Origin`;
2121
- `Path`;
2222
- `Parameters`;
2323
- `Fragment`.
24-
- **Domain** tries to [obtain](https://github.com/tomasfn87/url-parser/blob/main/index.html#L218) the site's icon (`favicon`) using a Google API;
24+
- **Origin** tries to [obtain](https://github.com/tomasfn87/url-parser/blob/main/index.html#L218) the site's icon (`favicon`) using a Google API;
2525
- **Parameters** and **Fragment** are [parsed](https://github.com/tomasfn87/url-parser/blob/main/index.html#L25) into `key` and (optional) `value`;
2626
- **Decode**: press the [`Decode`](https://github.com/tomasfn87/url-parser/blob/main/index.html#L161) button to solve encoded characters and actually read the URL's content.
2727

README.pt-br.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
### Descrição
1818

1919
- [Divide](https://github.com/tomasfn87/url-parser/blob/main/index.html#L42) a URL em 4 partes:
20-
- `Domínio`;
20+
- `Origem`;
2121
- `Caminho`;
2222
- `Parâmetros`;
2323
- `Fragmento`.
24-
- **Domínio** tenta [obter](https://github.com/tomasfn87/url-parser/blob/main/index.html#L218) o ícone do site (`favicon`) usando uma API do Google;
24+
- **Origem** tenta [obter](https://github.com/tomasfn87/url-parser/blob/main/index.html#L218) o ícone do site (`favicon`) usando uma API do Google;
2525
- **Parâmetros** e **Fragmento** são [divididos](https://github.com/tomasfn87/url-parser/blob/main/index.html#L25) em `chave` e `valor` (opcional);
2626
- **Decodificar**: aperte o botão [`Decodificar`](https://github.com/tomasfn87/url-parser/blob/main/index.html#L161) para resolver caracteres codificados e de fato ler o conteúdo da URL.
2727

c++/inc/url_parser/url_parser.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct KeyOptionalValueData {
1717
};
1818

1919
struct ParsedUrl {
20-
std::string domain;
20+
std::string origin;
2121
std::string path;
2222
KeyOptionalValueData parameter;
2323
KeyOptionalValueData fragment;
@@ -55,7 +55,7 @@ class Url {
5555
const std::string color_4 = "\x1b[34m";
5656
const std::string color_4_1 = "\x1b[94m";
5757
const std::string color_str(std::string str, std::string color);
58-
const std::vector<char> domain_chars = {':', '/', '.'};
58+
const std::vector<char> origin_chars = {':', '/', '.'};
5959
const std::vector<char> path_chars = {'/'};
6060
const std::vector<char> key_value_delimiters = {'='};
6161
const std::vector<char> key_optional_value_chars = {'?', '#', '&', '/'};

c++/src/url_parser/url_parser.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ bool Url::is_valid() {
5353
void Url::parse_url() {
5454
std::smatch parts;
5555
if (std::regex_match(url, parts, url_parts)) {
56-
parsed_url.domain = parts[1].str();
56+
parsed_url.origin = parts[1].str();
5757
if (parts[2].str().size())
5858
parsed_url.path = parts[2].str();
5959
else
@@ -134,7 +134,7 @@ const std::string Url::color_chars(
134134
}
135135

136136
const void Url::print_colored_url(bool decode) {
137-
std::string d = parsed_url.domain;
137+
std::string d = parsed_url.origin;
138138
std::string p = parsed_url.path;
139139
std::string q = parsed_url.parameter.base_string;
140140
std::string f = parsed_url.fragment.base_string;
@@ -145,7 +145,7 @@ const void Url::print_colored_url(bool decode) {
145145
f = decode_uri_component(f);
146146
}
147147
std::cout
148-
<< color_chars(domain_chars, d, "", color_1_1, "")
148+
<< color_chars(origin_chars, d, "", color_1_1, "")
149149
<< color_chars(path_chars, p, "", color_2_1, "")
150150
<< color_chars(
151151
key_optional_value_chars, q, "", color_3_1, color_dim)
@@ -207,7 +207,7 @@ const void Url::print_key_optional_value_list(
207207
}
208208

209209
const void Url::print_parsed_url(bool decode) {
210-
std::string d = parsed_url.domain;
210+
std::string d = parsed_url.origin;
211211
std::string p = parsed_url.path;
212212
std::string q = parsed_url.parameter.base_string;
213213
std::string f = parsed_url.fragment.base_string;
@@ -218,8 +218,8 @@ const void Url::print_parsed_url(bool decode) {
218218
f = decode_uri_component(f);
219219
}
220220
std::cout << color_str("", color_dim) << " "
221-
<< color_str("Domain", color_1) << color_str(":", color_dim)
222-
<< " " << color_chars(domain_chars, d, color_1_1, "", "") << "\n"
221+
<< color_str("Origin", color_1) << color_str(":", color_dim)
222+
<< " " << color_chars(origin_chars, d, color_1_1, "", "") << "\n"
223223
<< color_str("", color_dim) << " " << color_str("Path", color_2)
224224
<< color_str(":", color_dim) << " "
225225
<< color_chars(path_chars, p, color_2_1, "", "") << "\n";

index.html

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
if (!match) {
4646
return undefined;
4747
}
48-
const domain = match[1] || '';
48+
const origin = match[1] || '';
4949
const path = match[2] || '/';
5050
const queryString = match[3] || '';
5151
const hashString = match[4] || '';
@@ -55,13 +55,13 @@
5555
hashString.length > 1 && parseKeyOptionalValue(hashString, fragment, regexp.Fragment);
5656
return {
5757
parts: {
58-
domain: domain,
58+
origin: origin,
5959
path: path,
6060
parameters: parameters,
6161
fragment: fragment
6262
},
6363
fullUrl: function () {
64-
return domain + path + queryString + hashString;
64+
return origin + path + queryString + hashString;
6565
}
6666
};
6767
};
@@ -202,7 +202,7 @@ <h2>Analysis Result:</h2>
202202

203203
let isOdd = true;
204204

205-
const addTableRow = (label, value, isOdd, isSubtable = false, isDomainRow = false, domain = '') => {
205+
const addTableRow = (label, value, isOdd, isSubtable = false, isOriginRow = false, origin = '') => {
206206
const row = parsedResultTableBody.insertRow();
207207
const bgColor = isOdd ? (isSubtable ? '#2a2a2a' : '#222') : (isSubtable ? '#333' : '#282828');
208208
row.style.backgroundColor = bgColor;
@@ -214,35 +214,35 @@ <h2>Analysis Result:</h2>
214214
labelCell.style.paddingRight = '15px';
215215
valueCell.style.color = '#ccc';
216216
valueCell.style.backgroundColor = isOdd ? (isSubtable ? '' : '#333') : (isSubtable ? '' : '#3a3a3a');
217-
if (isDomainRow && domain) {
218-
const faviconUrl = `https://t2.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=${`https://${domain.replace(/^\s*\w+:\/\//, '')}`}&size=18`;
217+
if (isOriginRow && origin) {
218+
const faviconUrl = `https://t2.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=${`https://${origin.replace(/^\s*\w+:\/\//, '')}`}&size=18`;
219219
const faviconImg = document.createElement('img');
220220
faviconImg.src = faviconUrl;
221221
faviconImg.width = 18;
222222
faviconImg.height = 18;
223223
faviconImg.style.marginRight = '8px';
224224
faviconImg.style.verticalAlign = 'middle';
225225

226-
const domainLink = document.createElement('a');
227-
domainLink.href = `https://${domain.replace(/^\s*\w+:\/\//, '')}`;
228-
domainLink.className = 'url-link';
229-
domainLink.textContent = domain;
226+
const originLink = document.createElement('a');
227+
originLink.href = `https://${origin.replace(/^\s*\w+:\/\//, '')}`;
228+
originLink.className = 'url-link';
229+
originLink.textContent = origin;
230230

231231
valueCell.innerHTML = '';
232232

233233
faviconImg.onload = function() {
234234
valueCell.appendChild(faviconImg);
235-
valueCell.appendChild(domainLink);
235+
valueCell.appendChild(originLink);
236236
};
237237
faviconImg.onerror = function() {
238-
valueCell.appendChild(domainLink);
238+
valueCell.appendChild(originLink);
239239
};
240240
}
241241
};
242-
let domain = r.parts.domain;
242+
let origin = r.parts.origin;
243243
let fullUrl = r.fullUrl();
244244
let path = r.parts.path;
245-
addTableRow("Domain", domain, isOdd, false, true, domain);
245+
addTableRow("Origin", origin, isOdd, false, true, origin);
246246
isOdd = !isOdd;
247247
addTableRow("Path", path, isOdd);
248248
isOdd = !isOdd;
@@ -305,7 +305,7 @@ <h2>Analysis Result:</h2>
305305
addTableRow("Full URL", `<a href="${`https://${fullUrl.replace(/^\s*\w+:\/\//, '')}`}" class="url-link">${decode?decodeURIComponent(fullUrl):fullUrl}</a>`, isOdd);
306306

307307
let link = 'https://'
308-
+ parsed_self_url.parts.domain.replace(/^\w+:\/\//, '')
308+
+ parsed_self_url.parts.origin.replace(/^\w+:\/\//, '')
309309
+ parsed_self_url.parts.path
310310

311311
// YouTube Playlist
@@ -483,7 +483,7 @@ <h2>Analysis Result:</h2>
483483
);
484484
spotifyPlayer.contentWindow.postMessage({
485485
type: 'listeningOn',
486-
domain: window.location.hostname,
486+
origin: window.location.hostname,
487487
gtmId: 'MXNVD4PJ'
488488
}, 'https://open.spotify.com');
489489
}, 250);

js/main.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const main = () => {
1212
}
1313
let decode = false;
1414
const r = new Url({ url: input });
15-
if (!r.parsedUrl.parts.domain) {
15+
if (!r.parsedUrl.parts.origin) {
1616
console.log("Invalid URL.");
1717
return;
1818
}
@@ -46,9 +46,9 @@ const main = () => {
4646
return;
4747
}
4848
const {title, subtitle, content} = loadConfigFile("config.json");
49-
color.log(title, "Domain");
49+
color.log(title, "Origin");
5050
process.stdout.write(":\n- ");
51-
color.log(content, `${r.getDomain()}\n`);
51+
color.log(content, `${r.getOrigin()}\n`);
5252
if (r.parsedUrl.parts.path) {
5353
color.log(title, "Path");
5454
process.stdout.write(":\n- ");

js/src/url-parser.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export default class Url {
33
this.url = data.url;
44
this.parsedUrl = {
55
parts: {
6-
domain: '',
6+
origin: '',
77
path: '',
88
parameters: { str: '', list: [], obj: {} },
99
fragment: { str: '', list: [], obj: {} }
@@ -26,7 +26,7 @@ export default class Url {
2626
parseUrl() {
2727
if (this.RegExp().UrlParts.test(this.url)) {
2828
const groups = this.RegExp().UrlParts.exec(this.url);
29-
this.parsedUrl.parts.domain = groups[1];
29+
this.parsedUrl.parts.origin = groups[1];
3030
this.parsedUrl.parts.path = groups[2] || '/';
3131
this.parsedUrl.parts.parameters.str = groups[3] || '';
3232
this.parseKeyOptionalValue(
@@ -54,8 +54,8 @@ export default class Url {
5454
}
5555
}
5656

57-
getDomain() {
58-
return this.parsedUrl.parts.domain
57+
getOrigin() {
58+
return this.parsedUrl.parts.origin
5959
}
6060

6161
getPath() {
@@ -71,7 +71,7 @@ export default class Url {
7171
}
7272

7373
getFullUrl() {
74-
return this.getDomain() + this.getPath() + this.getParameters()
74+
return this.getOrigin() + this.getPath() + this.getParameters()
7575
+ this.getFragment()
7676
}
7777

js/test/url-parser.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { ClassMethodTest, ClassMethodTester }
22
from '../util/test-class-method.js';
33
import Url from '../src/url-parser.js';
44

5-
const getDomainTest = new ClassMethodTest(Url, "getDomain", [], "Url.getDomain");
6-
getDomainTest.addTestCases([
5+
const getOriginTest = new ClassMethodTest(Url, "getOrigin", [], "Url.getOrigin");
6+
getOriginTest.addTestCases([
77
{
88
input: { url: "https://tagassistant.google.com/?hl=en&utm_source=gtm#/?source=TAG_MANAGER&id=GTM-MXNVD4PJ&gtm_auth=H0X5tN2DEEpfJ0eha8q7Ig&gtm_preview=env-5&cb=5607611040920180" },
99
keys: [ "url" ],
@@ -173,7 +173,7 @@ getFullUrlTest.addTestCases([
173173
]);
174174

175175
const tester = new ClassMethodTester();
176-
tester.addTestSet(getDomainTest);
176+
tester.addTestSet(getOriginTest);
177177
tester.addTestSet(getPathTest);
178178
tester.addTestSet(getParametersTest);
179179
tester.addTestSet(getFragmentTest);

0 commit comments

Comments
 (0)