Skip to content

Commit a922e55

Browse files
authored
Merge pull request #250 from jshemas/sep-16
remove new lines from jsonLD
2 parents 98e7f2b + 419232f commit a922e55

File tree

8 files changed

+179
-91
lines changed

8 files changed

+179
-91
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## 6.8.2
4+
5+
- Remove new lines from jsonLD.
6+
- If url string is not `isLatin1` then encode it, otherwise you will run into `ByteString` errors within `fetch`
7+
- Updating dependencies
8+
39
## 6.8.1
410

511
- Fixing issue where setting `fetchOptions.headers` would replace the default `headers`

lib/extract.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export default function extractMetaTags(body: string, options: OpenGraphScraperO
9797
if (!ogObject.jsonLD) ogObject.jsonLD = [];
9898
let scriptText = $(script).text();
9999
if (scriptText) {
100+
scriptText = scriptText.replace(/(\r\n|\n|\r)/gm, ''); // remove newlines
100101
scriptText = unescapeScriptText(scriptText);
101102
ogObject.jsonLD.push(JSON.parse(scriptText));
102103
}

lib/request.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,18 @@ export default async function requestAndResultsFormatter(options: OpenGraphScrap
4848
let body;
4949
let response;
5050
try {
51+
// eslint-disable-next-line no-control-regex
52+
const isLatin1 = /^[\u0000-\u00ff]{0,}$/;
53+
54+
let url = options.url ?? '';
55+
if (!isLatin1.test(url)) url = encodeURI(url);
56+
5157
response = await fetch(
52-
options.url ?? '',
58+
url ?? '',
5359
{
5460
signal: AbortSignal.timeout((options.timeout ?? 10) * 1000),
5561
...options.fetchOptions,
56-
headers: { Origin: options.url ?? '', Accept: 'text/html', ...options.fetchOptions?.headers },
62+
headers: { Origin: url ?? '', Accept: 'text/html', ...options.fetchOptions?.headers },
5763
},
5864
);
5965

package-lock.json

Lines changed: 83 additions & 82 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "open-graph-scraper",
33
"description": "Node.js scraper module for Open Graph and Twitter Card info",
4-
"version": "6.8.1",
4+
"version": "6.8.2",
55
"license": "MIT",
66
"main": "./dist/cjs/index.js",
77
"types": "./types/index.d.ts",
@@ -48,21 +48,21 @@
4848
"CHANGELOG.md"
4949
],
5050
"devDependencies": {
51-
"@snyk/protect": "^1.1293.0",
52-
"@types/mocha": "^10.0.7",
53-
"@types/node": "^18.19.47",
51+
"@snyk/protect": "^1.1293.1",
52+
"@types/mocha": "^10.0.8",
53+
"@types/node": "^18.19.50",
5454
"@typescript-eslint/eslint-plugin": "^7.18.0",
5555
"@typescript-eslint/parser": "^7.18.0",
5656
"chai": "^4.5.0",
5757
"eslint": "^8.57.0",
5858
"eslint-config-airbnb-base": "^15.0.0",
5959
"eslint-config-airbnb-typescript": "^18.0.0",
60-
"eslint-plugin-import": "^2.29.1",
60+
"eslint-plugin-import": "^2.30.0",
6161
"eslint-plugin-mocha": "^10.5.0",
6262
"eslint-plugin-promise": "^7.1.0",
6363
"mocha": "^10.7.3",
6464
"nyc": "^17.0.0",
65-
"sinon": "^18.0.0",
65+
"sinon": "^19.0.2",
6666
"ts-mocha": "^10.0.0",
6767
"typescript": "^5.5.4"
6868
},

tests/integration/basic.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,8 @@ describe('basic', function () {
465465
});
466466
});
467467

468-
it('epicgames.com - should return og data using a header', function () {
468+
// todo: this test no longer works in github ci
469+
it.skip('epicgames.com - should return og data using a header', function () {
469470
return ogs({
470471
url: 'https://dev.epicgames.com/documentation/ja-jp/unreal-engine/volume-actors-in-unreal-engine',
471472
fetchOptions: {

0 commit comments

Comments
 (0)