Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove new lines from jsonLD #250

Merged
merged 6 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## 6.8.2

- Remove new lines from jsonLD.
- If url string is not `isLatin1` then encode it, otherwise you will run into `ByteString` errors within `fetch`
- Updating dependencies

## 6.8.1

- Fixing issue where setting `fetchOptions.headers` would replace the default `headers`
Expand Down
1 change: 1 addition & 0 deletions lib/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
$('meta').each((index, meta) => {
if (!meta.attribs || (!meta.attribs.property && !meta.attribs.name)) return;
const property = meta.attribs.property || meta.attribs.name;
const content: any = meta.attribs.content || meta.attribs.value;

Check warning on line 27 in lib/extract.ts

View workflow job for this annotation

GitHub Actions / buildAndTest (18)

Unexpected any. Specify a different type

Check warning on line 27 in lib/extract.ts

View workflow job for this annotation

GitHub Actions / buildAndTest (20)

Unexpected any. Specify a different type

Check warning on line 27 in lib/extract.ts

View workflow job for this annotation

GitHub Actions / buildAndTest (22)

Unexpected any. Specify a different type
metaFields.forEach((item) => {
if (item && property.toLowerCase() === item.property.toLowerCase()) {
// check if fieldName is one of mediaMapperProperties
Expand Down Expand Up @@ -57,10 +57,10 @@
if (!ogObject[item.fieldName]) {
ogObject[item.fieldName] = [content];
} else {
ogObject[item.fieldName]?.push(content);

Check warning on line 60 in lib/extract.ts

View workflow job for this annotation

GitHub Actions / buildAndTest (18)

Unsafe argument of type `any` assigned to a parameter of type `string`

Check warning on line 60 in lib/extract.ts

View workflow job for this annotation

GitHub Actions / buildAndTest (20)

Unsafe argument of type `any` assigned to a parameter of type `string`

Check warning on line 60 in lib/extract.ts

View workflow job for this annotation

GitHub Actions / buildAndTest (22)

Unsafe argument of type `any` assigned to a parameter of type `string`
}
} else {
ogObject[item.fieldName] = content;

Check warning on line 63 in lib/extract.ts

View workflow job for this annotation

GitHub Actions / buildAndTest (18)

Unsafe assignment of an `any` value

Check warning on line 63 in lib/extract.ts

View workflow job for this annotation

GitHub Actions / buildAndTest (20)

Unsafe assignment of an `any` value

Check warning on line 63 in lib/extract.ts

View workflow job for this annotation

GitHub Actions / buildAndTest (22)

Unsafe assignment of an `any` value
}
}
});
Expand All @@ -70,7 +70,7 @@
if (!ogObject.customMetaTags) ogObject.customMetaTags = {};
if (item && property.toLowerCase() === item.property.toLowerCase()) {
if (!item.multiple) {
ogObject.customMetaTags[item.fieldName] = content;

Check warning on line 73 in lib/extract.ts

View workflow job for this annotation

GitHub Actions / buildAndTest (18)

Unsafe assignment of an `any` value

Check warning on line 73 in lib/extract.ts

View workflow job for this annotation

GitHub Actions / buildAndTest (20)

Unsafe assignment of an `any` value

Check warning on line 73 in lib/extract.ts

View workflow job for this annotation

GitHub Actions / buildAndTest (22)

Unsafe assignment of an `any` value
} else if (!ogObject.customMetaTags[item.fieldName]) {
ogObject.customMetaTags[item.fieldName] = [content];
} else if (Array.isArray(ogObject.customMetaTags[item.fieldName])) {
Expand All @@ -97,8 +97,9 @@
if (!ogObject.jsonLD) ogObject.jsonLD = [];
let scriptText = $(script).text();
if (scriptText) {
scriptText = scriptText.replace(/(\r\n|\n|\r)/gm, ''); // remove newlines
scriptText = unescapeScriptText(scriptText);
ogObject.jsonLD.push(JSON.parse(scriptText));

Check warning on line 102 in lib/extract.ts

View workflow job for this annotation

GitHub Actions / buildAndTest (18)

Unsafe argument of type `any` assigned to a parameter of type `object`

Check warning on line 102 in lib/extract.ts

View workflow job for this annotation

GitHub Actions / buildAndTest (20)

Unsafe argument of type `any` assigned to a parameter of type `object`

Check warning on line 102 in lib/extract.ts

View workflow job for this annotation

GitHub Actions / buildAndTest (22)

Unsafe argument of type `any` assigned to a parameter of type `object`
}
}
});
Expand Down
10 changes: 8 additions & 2 deletions lib/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,18 @@ export default async function requestAndResultsFormatter(options: OpenGraphScrap
let body;
let response;
try {
// eslint-disable-next-line no-control-regex
const isLatin1 = /^[\u0000-\u00ff]{0,}$/;

let url = options.url ?? '';
if (!isLatin1.test(url)) url = encodeURI(url);

response = await fetch(
options.url ?? '',
url ?? '',
{
signal: AbortSignal.timeout((options.timeout ?? 10) * 1000),
...options.fetchOptions,
headers: { Origin: options.url ?? '', Accept: 'text/html', ...options.fetchOptions?.headers },
headers: { Origin: url ?? '', Accept: 'text/html', ...options.fetchOptions?.headers },
},
);

Expand Down
165 changes: 83 additions & 82 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "open-graph-scraper",
"description": "Node.js scraper module for Open Graph and Twitter Card info",
"version": "6.8.1",
"version": "6.8.2",
"license": "MIT",
"main": "./dist/cjs/index.js",
"types": "./types/index.d.ts",
Expand Down Expand Up @@ -48,21 +48,21 @@
"CHANGELOG.md"
],
"devDependencies": {
"@snyk/protect": "^1.1293.0",
"@types/mocha": "^10.0.7",
"@types/node": "^18.19.47",
"@snyk/protect": "^1.1293.1",
"@types/mocha": "^10.0.8",
"@types/node": "^18.19.50",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"chai": "^4.5.0",
"eslint": "^8.57.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^18.0.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-import": "^2.30.0",
"eslint-plugin-mocha": "^10.5.0",
"eslint-plugin-promise": "^7.1.0",
"mocha": "^10.7.3",
"nyc": "^17.0.0",
"sinon": "^18.0.0",
"sinon": "^19.0.2",
"ts-mocha": "^10.0.0",
"typescript": "^5.5.4"
},
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,8 @@ describe('basic', function () {
});
});

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