Skip to content

Commit

Permalink
Fix code scanning alert #2: DOM text reinterpreted as HTML
Browse files Browse the repository at this point in the history
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
  • Loading branch information
jeffpaul and github-advanced-security[bot] authored Sep 19, 2024
1 parent cf96557 commit 496f3ff
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions assets/js/admin-pull.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ import { __ } from '@wordpress/i18n';

const { document } = window;

/**
* Escape special characters in URL components.
*
* @param {string} str The string to escape.
* @return {string} The escaped string.
*/
const escapeURLComponent = (str) => {

Check failure on line 15 in assets/js/admin-pull.js

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

assets/js/admin-pull.js#L15

[prettier/prettier] Replace `str` with `·str·`
return encodeURIComponent(str).replace(/[!'()*]/g, (c) => {

Check failure on line 16 in assets/js/admin-pull.js

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

assets/js/admin-pull.js#L16

[prettier/prettier] Replace `····return·encodeURIComponent(str).replace(/[!'()*]/g,·(c` with `↹return·encodeURIComponent(·str·).replace(·/[!'()*]/g,·(·c·`
return '%' + c.charCodeAt(0).toString(16);

Check failure on line 17 in assets/js/admin-pull.js

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

assets/js/admin-pull.js#L17

[prettier/prettier] Replace `········return·'%'·+·c.charCodeAt(0).toString(16` with `↹↹return·'%'·+·c.charCodeAt(·0·).toString(·16·`
});

Check failure on line 18 in assets/js/admin-pull.js

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

assets/js/admin-pull.js#L18

[prettier/prettier] Replace `····}` with `↹}·`
};

const chooseConnection = document.getElementById( 'pull_connections' );
const choosePostType = document.getElementById( 'pull_post_type' );
const choosePostTypeBtn = document.getElementById( 'pull_post_type_submit' );
Expand Down Expand Up @@ -83,11 +95,11 @@ if ( chooseConnection && choosePostType && form ) {
*/
const getURL = () => {
const postType =
choosePostType.options[ choosePostType.selectedIndex ].value;
escapeURLComponent(choosePostType.options[ choosePostType.selectedIndex ].value);

Check failure on line 98 in assets/js/admin-pull.js

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

assets/js/admin-pull.js#L97-L98

[prettier/prettier] Replace `⏎↹↹escapeURLComponent(choosePostType.options[·choosePostType.selectedIndex·].value` with `·escapeURLComponent(⏎↹↹choosePostType.options[·choosePostType.selectedIndex·].value⏎↹`
const baseURL =
chooseConnection.options[ chooseConnection.selectedIndex ].getAttribute(
escapeURLComponent(chooseConnection.options[ chooseConnection.selectedIndex ].getAttribute(

Check failure on line 100 in assets/js/admin-pull.js

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

assets/js/admin-pull.js#L99-L100

[prettier/prettier] Replace `⏎↹↹escapeURLComponent(` with `·escapeURLComponent(⏎↹↹`
'data-pull-url'
);
));

Check failure on line 102 in assets/js/admin-pull.js

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

assets/js/admin-pull.js#L102

[prettier/prettier] Insert `⏎↹`
let status = 'new';

if ( -1 < ` ${ form.className } `.indexOf( ' status-skipped ' ) ) {
Expand Down

0 comments on commit 496f3ff

Please sign in to comment.