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(references): check if object value is a string before replacement #682

Merged
merged 1 commit into from
Aug 19, 2021
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
20 changes: 18 additions & 2 deletions __tests__/utils/reference/getReferences.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,17 @@ const properties = {
color: "{color.red.value}",
width: "{size.border.value}",
style: "solid"
}
},
},
secondary: {
// and objects that have a non-string
value: {
color: "{color.red.value}",
width: 2,
style: "solid"
}
},
tertiary: {
// getReferences should work on interpolated values like this:
value: "{size.border.value} solid {color.red.value}"
}
Expand Down Expand Up @@ -65,8 +73,16 @@ describe('utils', () => {
);
});

it(`should work with interpolated values`, () => {
it(`should work with objects that have numbers`, () => {
expect(dictionary.getReferences(properties.border.secondary.value)).toEqual(
expect.arrayContaining([
{value: "#f00"}
])
);
});

it(`should work with interpolated values`, () => {
expect(dictionary.getReferences(properties.border.tertiary.value)).toEqual(
expect.arrayContaining([
{value: "2px"},
{value: "#f00"}
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/references/getReferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function getReferences(value) {
// function which iterates over the object to see if there is a reference
if (typeof value === 'object') {
for (const key in value) {
if (value.hasOwnProperty(key)) {
if (value.hasOwnProperty(key) && typeof value[key] === 'string') {
value[key].replace(regex, findReference);
}
}
Expand Down