Skip to content
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
2 changes: 1 addition & 1 deletion 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 @@ -95,11 +95,11 @@
$('script').each((index, script) => {
if (script.attribs.type && script.attribs.type === 'application/ld+json') {
if (!ogObject.jsonLD) ogObject.jsonLD = [];
let scriptText = $(script).text();
let scriptText = $(script).text().trim();
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
22 changes: 22 additions & 0 deletions tests/unit/static.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,28 @@ describe('static check meta tags', function () {
});
});

it('jsonLD - empty with whitespace', function () {
const metaHTML = `<html><head>
<script type="application/ld+json">


</script>
</head></html>`;

mockAgent.get('http://www.test.com')
.intercept({ path: '/' })
.reply(200, metaHTML);

return ogs({ url: 'www.test.com' })
.then(function (data) {
expect(data.result.success).to.be.eql(true);
expect(data.result.requestUrl).to.be.eql('http://www.test.com');
expect(data.result.jsonLD).to.be.eql([]);
expect(data.html).to.be.eql(metaHTML);
expect(data.response).to.be.a('response');
});
});

it('encoding - utf-8', function () {
/* eslint-disable max-len */
const metaHTML = `<html><head>
Expand Down
Loading