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

Fix: no-invalid-meta crashes for non Object values (fixes #10750) #10753

Merged
merged 1 commit into from Aug 18, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/tools/internal-rules/no-invalid-meta.js
Expand Up @@ -126,6 +126,24 @@ ruleTester.run("no-invalid-meta", rule, {
column: 18
}]
},
{
code: [
"module.exports = {",
" meta: [],",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meta could be an object. is the [] intentional?

Copy link
Contributor Author

@s4san s4san Aug 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. In case of an emtpy object, node.properties is [] but for any other type it is undefined resulting in a crash. I intentionally declared meta as an array to elicit this case

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.thanks for the clarification!


" create: function(context) {",
" return {",
" Program: function(node) {}",
" };",
" }",
"};"
].join("\n"),
errors: [{
message: "Rule is missing a meta.docs property.",
line: 2,
column: 5
}]
},
{
code: [
"module.exports = {",
Expand Down
6 changes: 6 additions & 0 deletions tools/internal-rules/consistent-docs-description.js
Expand Up @@ -25,6 +25,12 @@ const ALLOWED_FIRST_WORDS = [
function getPropertyFromObject(property, node) {
const properties = node.properties;

if (!Array.isArray(properties)) {

// if properties is not an array, "internal-no-invalid-meta" will already report this.
return null;
}

for (let i = 0; i < properties.length; i++) {
if (properties[i].key.name === property) {
return properties[i];
Expand Down
6 changes: 6 additions & 0 deletions tools/internal-rules/consistent-docs-url.js
Expand Up @@ -21,6 +21,12 @@ const path = require("path");
function getPropertyFromObject(property, node) {
const properties = node.properties;

if (!Array.isArray(properties)) {

// if properties is not an array, "internal-no-invalid-meta" will already report this.
return null;
}

for (let i = 0; i < properties.length; i++) {
if (properties[i].key.name === property) {
return properties[i];
Expand Down
5 changes: 5 additions & 0 deletions tools/internal-rules/no-invalid-meta.js
Expand Up @@ -19,6 +19,11 @@
function getPropertyFromObject(property, node) {
const properties = node.properties;

if (!Array.isArray(properties)) {

return null;
}

for (let i = 0; i < properties.length; i++) {
if (properties[i].key.name === property) {
return properties[i];
Expand Down