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

Improper if condition for image's style width attribute #48

Merged
merged 11 commits into from
Jul 2, 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
7 changes: 6 additions & 1 deletion .github/workflows/jira.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
pull_request:
types: [opened]
jobs:
security:
security-jira:
if: ${{ github.actor == 'dependabot[bot]' || github.actor == 'snyk-bot' || contains(github.event.pull_request.head.ref, 'snyk-fix-') || contains(github.event.pull_request.head.ref, 'snyk-upgrade-')}}
runs-on: ubuntu-latest
steps:
Expand All @@ -26,3 +26,8 @@ jobs:
PR: ${{ github.event.pull_request.html_url }}

fields: "${{ secrets.JIRA_FIELDS }}"
- name: Transition issue
uses: atlassian/gajira-transition@v3
with:
issue: ${{ steps.create.outputs.issue }}
transition: ${{ secrets.JIRA_TRANSITION }}
11 changes: 11 additions & 0 deletions .github/workflows/sast-scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: SAST Scan
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
security-sast:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Semgrep Scan
run: docker run -v /var/run/docker.sock:/var/run/docker.sock -v "${PWD}:/src" returntocorp/semgrep semgrep scan --config auto
2 changes: 1 addition & 1 deletion .github/workflows/sca-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
security:
security-sca:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
Expand Down
4 changes: 2 additions & 2 deletions src/toRedactor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ export const toRedactor = (jsonValue: any,options?:IJsonToHtmlOptions) : string
if (attrsJson['width']) {
let width = attrsJson['width']
if (width.slice(width.length - 1) === '%') {
style = `width: ${allattrs['width']}; height: ${attrsJson['height'] ? attrsJson['height'] : 'auto'};`
} else {
style = `width: ${allattrs['width'] + '%'}; height: ${attrsJson['height'] ? attrsJson['height'] : 'auto'};`
} else {
style = `width: ${allattrs['width']}; height: ${attrsJson['height'] ? attrsJson['height'] : 'auto'};`
}
} else {
if (allattrs['width']) {
Expand Down
95 changes: 93 additions & 2 deletions test/expectedJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ export default {
]
}
],
"htmlUpdated": "<p></p><img asset_uid=\"blt5523ee02703e39f5\" src=\"https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blt5523ee02703e39f5/60dc421ee5e22614ef8dadfa/captain_pardip.jpg\" width=\"24.193548387096776\" height=\"auto\" style=\"width: 24.193548387096776%; height: auto;height: auto;\" type=\"asset\" sys-style-type=\"download\"/><p></p><iframe src=\"https://www.youtube.com/embed/CSvFpBOe8eY\"></iframe><img asset_uid=\"blta2aad0332073026c\" src=\"https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blta2aad0332073026c/60dc3bf8214cd714eebe026b/logo_1.jpg\" height=\"auto\" type=\"asset\" sys-style-type=\"download\"/>"
"htmlUpdated": "<p></p><img asset_uid=\"blt5523ee02703e39f5\" src=\"https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blt5523ee02703e39f5/60dc421ee5e22614ef8dadfa/captain_pardip.jpg\" width=\"24.193548387096776\" height=\"auto\" style=\"width: 24.193548387096776; height: auto;height: auto;\" type=\"asset\" sys-style-type=\"download\"/><p></p><iframe src=\"https://www.youtube.com/embed/CSvFpBOe8eY\"></iframe><img asset_uid=\"blta2aad0332073026c\" src=\"https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blta2aad0332073026c/60dc3bf8214cd714eebe026b/logo_1.jpg\" height=\"auto\" type=\"asset\" sys-style-type=\"download\"/>"
},
"7": {
"html": "<p>this is <a href=\"link.com\" target=\"_self\">link</a></p><p></p><div data-type='hr' style='border-top: 3px solid #bbb'></div><p></p><p class=\"className\">paragraph with class</p><p id=\"id\">paragraph with id</p>",
Expand Down Expand Up @@ -1909,6 +1909,97 @@ export default {
}
]
}
},
"RT-154": {
"html": "<p></p><img asset_uid=\"blt5523ee02703e39f5\" src=\"https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blt5523ee02703e39f5/60dc421ee5e22614ef8dadfa/captain_pardip.jpg\" width=\"24.193548387096776\" height=\"auto\" style=\"width: 24.193548387096776; height: auto;\"/><p></p><iframe src=\"https://www.youtube.com/embed/CSvFpBOe8eY\"></iframe><img asset_uid=\"blta2aad0332073026c\" src=\"https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blta2aad0332073026c/60dc3bf8214cd714eebe026b/logo_1.jpg\" height=\"auto\"/>",
"json": [
{
"type": "p",
"attrs": {},
"uid": "67d60b59926c48b58cb6b5d899401c01",
"children": [
{
"text": ""
}
]
},
{
"type": "reference",
"attrs": {
"asset-link": "https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blt5523ee02703e39f5/60dc421ee5e22614ef8dadfa/captain_pardip.jpg",
"default": true,
"asset-type": "image/jpg",
"display-type": "display",
"type": "asset",
"style": {
"height": "auto"
},
"redactor-attributes": {
"asset_uid": "blt5523ee02703e39f5",
"src": "https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blt5523ee02703e39f5/60dc421ee5e22614ef8dadfa/captain_pardip.jpg",
"width": "24.193548387096776%",
"height": "auto",
"style": "width: 24.193548387096776; height: auto;"
},
"width": 24.193548387096776
},
"uid": "fe969de8727c4074a23442a71b57ebb8",
"children": [
{
"text": ""
}
]
},
{
"type": "p",
"attrs": {},
"uid": "8c912298ad0a4a458c189f12603c05fb",
"children": [
{
"text": ""
}
]
},
{
"type": "embed",
"attrs": {
"src": "https://www.youtube.com/embed/CSvFpBOe8eY",
"style": {},
"redactor-attributes": {
"src": "https://www.youtube.com/embed/CSvFpBOe8eY"
}
},
"uid": "26067652d613404b8091f6e83d7af301",
"children": [
{
"text": ""
}
]
},
{
"type": "reference",
"attrs": {
"asset-link": "https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blta2aad0332073026c/60dc3bf8214cd714eebe026b/logo_1.jpg",
"default": true,
"asset-type": "image/jpg",
"display-type": "display",
"type": "asset",
"style": {},
"redactor-attributes": {
"asset_uid": "blta2aad0332073026c",
"src": "https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blta2aad0332073026c/60dc3bf8214cd714eebe026b/logo_1.jpg",
"height": "auto"
}
},
"uid": "d56e691f59ce4d35934c6aa9325188a2",
"children": [
{
"text": ""
}
]
}
],
"htmlUpdated": "<p></p><img asset_uid=\"blt5523ee02703e39f5\" src=\"https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blt5523ee02703e39f5/60dc421ee5e22614ef8dadfa/captain_pardip.jpg\" width=\"24.193548387096776\" height=\"auto\" style=\"width: 24.193548387096776%; height: auto;height: auto;\" type=\"asset\" sys-style-type=\"download\"/><p></p><iframe src=\"https://www.youtube.com/embed/CSvFpBOe8eY\"></iframe><img asset_uid=\"blta2aad0332073026c\" src=\"https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blta2aad0332073026c/60dc3bf8214cd714eebe026b/logo_1.jpg\" height=\"auto\" type=\"asset\" sys-style-type=\"download\"/>"
}

}
10 changes: 4 additions & 6 deletions test/toRedactor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ describe("Testing json to html conversion", () => {
let testResult = isEqual(htmlValue, expectedValue['5'].html)
expect(testResult).toBe(true)
})
it("Image and iframe conversion", () => {
let jsonValue = expectedValue["6"].json

let htmlValue = toRedactor({ type: "doc", attrs: {}, children: jsonValue })
let testResult = isEqual(htmlValue, expectedValue['6'].htmlUpdated)
expect(testResult).toBe(true)
it.each(["6", "RT-154"])("Image and iframe conversion", (index) => {
let jsonValue = expectedValue[index].json
let htmlValue = toRedactor({ type: "doc", attrs: {}, children: jsonValue })
expect(htmlValue).toBe(expectedValue[index].htmlUpdated)
})
it("Link ,divider and property conversion", () => {
let jsonValue = expectedValue["7"].json
Expand Down
Loading