Skip to content

Commit

Permalink
Merge pull request #239 from simonsymhoven/bug/jquery-escaping-meta-c…
Browse files Browse the repository at this point in the history
…haracters

escape js meta characters if using jQuery3
  • Loading branch information
uhafner authored Jun 19, 2022
2 parents 5e39cce + cbbf8c2 commit 63f78dc
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/main/resources/io/jenkins/plugins/echarts-common.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ Use it like <st:adjunct includes="io.jenkins.plugins.echarts-common"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/configurable-trend-chart.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/pie-chart.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/progress-chart.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/escapeMetaCharacters.js"/>

</j:jelly>
1 change: 1 addition & 0 deletions src/main/resources/io/jenkins/plugins/echarts-simple.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ Use it like <st:adjunct includes="io.jenkins.plugins.echarts-simple"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/configurable-trend-chart.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/pie-chart.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/progress-chart.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/escapeMetaCharacters.js"/>

</j:jelly>
1 change: 1 addition & 0 deletions src/main/resources/io/jenkins/plugins/echarts.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ Use it like <st:adjunct includes="io.jenkins.plugins.echarts"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/configurable-trend-chart.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/pie-chart.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/progress-chart.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/escapeMetaCharacters.js"/>

</j:jelly>
3 changes: 3 additions & 0 deletions src/main/webapp/js/escapeMetaCharacters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function escapeMetaCharacters(string) {
return string.replaceAll(/[.*+?^${}()|[\]\\]/g, '\\$&')
}
2 changes: 1 addition & 1 deletion src/main/webapp/js/pie-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jQuery3(document).ready(function () {
}
}

const chartPlaceHolder = jQuery3("#" + chartDivId);
const chartPlaceHolder = jQuery3("#" + escapeMetaCharacters(chartDivId));
const model = JSON.parse(chartPlaceHolder.attr('data-chart-model'));
const title = chartPlaceHolder.attr('data-title');
const chartDiv = chartPlaceHolder[0];
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/js/progress-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jQuery3(document).ready(function () {
* @param {String} chartDivId - the ID of the div where the chart should be shown in
*/
function renderProgressChart(chartDivId) {
const chartPlaceHolder = jQuery3("#" + chartDivId);
const chartPlaceHolder = jQuery3("#" + escapeMetaCharacters(chartDivId));
const model = JSON.parse(chartPlaceHolder.attr('data-chart-model'));
const title = chartPlaceHolder.attr('data-title');
const tooltip = chartPlaceHolder.attr('data-tooltip');
Expand Down

0 comments on commit 63f78dc

Please sign in to comment.