@realfavicongenerator/check-favicon 0.4.6 → 0.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -73,6 +73,21 @@ test('checkSvgFavicon - svgFaviconDeclared & svgFaviconCannotGet', () => __await
73
73
  }
74
74
  });
75
75
  }));
76
+ // For https://github.com/RealFaviconGenerator/core/issues/2
77
+ test('checkSvgFavicon - Protocol-relative URL', () => __awaiter(void 0, void 0, void 0, function* () {
78
+ yield runSvgTest(`<link rel="icon" type="image/svg+xml" href="//example.com/the-icon.svg" />`, [{
79
+ status: types_1.CheckerStatus.Ok,
80
+ id: types_1.MessageId.svgFaviconDeclared,
81
+ }, {
82
+ status: types_1.CheckerStatus.Error,
83
+ id: types_1.MessageId.svgFaviconCannotGet,
84
+ }], {
85
+ 'https://example.com/the-icon.svg': {
86
+ status: 403,
87
+ contentType: 'image/svg+xml'
88
+ }
89
+ });
90
+ }));
76
91
  test('checkSvgFavicon - svgFaviconDeclared & svgFaviconDownloadable & svgFaviconSquare', () => __awaiter(void 0, void 0, void 0, function* () {
77
92
  const testIconPath = './fixtures/happy-face.svg';
78
93
  const serpIcon = yield (0, helper_1.filePathToString)(testIconPath);
package/dist/helper.js CHANGED
@@ -145,8 +145,12 @@ const mergeUrlAndPath = (baseUrl, absoluteOrRelativePath) => {
145
145
  return absoluteOrRelativePath;
146
146
  }
147
147
  const url = new URL(baseUrl);
148
- // If the path starts with a slash, replace the pathname
149
- if (absoluteOrRelativePath.startsWith('/')) {
148
+ // Protocol-relative URL
149
+ if (absoluteOrRelativePath.startsWith('//')) {
150
+ return `${url.protocol}${absoluteOrRelativePath}`;
151
+ }
152
+ else if (absoluteOrRelativePath.startsWith('/')) {
153
+ // If the path starts with a slash, replace the pathname
150
154
  return `${url.origin}${absoluteOrRelativePath}`;
151
155
  }
152
156
  else {
@@ -112,6 +112,10 @@ test('mergeUrlAndPath', () => {
112
112
  expect((0, helper_1.mergeUrlAndPath)('https://example.com/sub-page', '/some-path')).toBe('https://example.com/some-path');
113
113
  expect((0, helper_1.mergeUrlAndPath)('https://example.com/sub-page', 'some/path')).toBe('https://example.com/sub-page/some/path');
114
114
  expect((0, helper_1.mergeUrlAndPath)('https://example.com', 'https://elsewhere.com/some-path')).toBe('https://elsewhere.com/some-path');
115
+ // Protocol-relative URL
116
+ // For https://github.com/RealFaviconGenerator/core/issues/2
117
+ expect((0, helper_1.mergeUrlAndPath)('https://example.com', '//elsewhere.com/some-path')).toBe('https://elsewhere.com/some-path');
118
+ expect((0, helper_1.mergeUrlAndPath)('http://example.com', '//elsewhere.com/some-other/path')).toBe('http://elsewhere.com/some-other/path');
115
119
  });
116
120
  test('parseSizesAttribute', () => {
117
121
  expect((0, helper_1.parseSizesAttribute)(null)).toEqual(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@realfavicongenerator/check-favicon",
3
- "version": "0.4.6",
3
+ "version": "0.4.7",
4
4
  "description": "Check the favicon of a website",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -38,6 +38,5 @@
38
38
  "decode-ico": "^0.4.1",
39
39
  "node-html-parser": "^6.1.13",
40
40
  "sharp": "^0.32.6"
41
- },
42
- "gitHead": "f62941a779e6ce1b49ad97bfea8a9eb71e7ceba5"
41
+ }
43
42
  }
@@ -76,6 +76,22 @@ test('checkSvgFavicon - svgFaviconDeclared & svgFaviconCannotGet', async () => {
76
76
  });
77
77
  })
78
78
 
79
+ // For https://github.com/RealFaviconGenerator/core/issues/2
80
+ test('checkSvgFavicon - Protocol-relative URL', async () => {
81
+ await runSvgTest(`<link rel="icon" type="image/svg+xml" href="//example.com/the-icon.svg" />`, [{
82
+ status: CheckerStatus.Ok,
83
+ id: MessageId.svgFaviconDeclared,
84
+ }, {
85
+ status: CheckerStatus.Error,
86
+ id: MessageId.svgFaviconCannotGet,
87
+ }], {
88
+ 'https://example.com/the-icon.svg': {
89
+ status: 403,
90
+ contentType: 'image/svg+xml'
91
+ }
92
+ });
93
+ })
94
+
79
95
  test('checkSvgFavicon - svgFaviconDeclared & svgFaviconDownloadable & svgFaviconSquare', async () => {
80
96
  const testIconPath = './fixtures/happy-face.svg';
81
97
 
@@ -117,6 +117,11 @@ test('mergeUrlAndPath', () => {
117
117
  expect(mergeUrlAndPath('https://example.com/sub-page', 'some/path')).toBe('https://example.com/sub-page/some/path');
118
118
 
119
119
  expect(mergeUrlAndPath('https://example.com', 'https://elsewhere.com/some-path')).toBe('https://elsewhere.com/some-path');
120
+
121
+ // Protocol-relative URL
122
+ // For https://github.com/RealFaviconGenerator/core/issues/2
123
+ expect(mergeUrlAndPath('https://example.com', '//elsewhere.com/some-path')).toBe('https://elsewhere.com/some-path');
124
+ expect(mergeUrlAndPath('http://example.com', '//elsewhere.com/some-other/path')).toBe('http://elsewhere.com/some-other/path');
120
125
  })
121
126
 
122
127
  test('parseSizesAttribute', () => {
package/src/helper.ts CHANGED
@@ -156,8 +156,11 @@ export const mergeUrlAndPath = (baseUrl: string, absoluteOrRelativePath: string)
156
156
 
157
157
  const url = new URL(baseUrl);
158
158
 
159
- // If the path starts with a slash, replace the pathname
160
- if (absoluteOrRelativePath.startsWith('/')) {
159
+ // Protocol-relative URL
160
+ if (absoluteOrRelativePath.startsWith('//')) {
161
+ return `${url.protocol}${absoluteOrRelativePath}`;
162
+ } else if (absoluteOrRelativePath.startsWith('/')) {
163
+ // If the path starts with a slash, replace the pathname
161
164
  return `${url.origin}${absoluteOrRelativePath}`;
162
165
  } else {
163
166
  // Otherwise, append the path to the existing pathname
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 RealFaviconGenerator
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.