Skip to content

Commit

Permalink
Fix SonarQube security issues
Browse files Browse the repository at this point in the history
  • Loading branch information
JamsonChan authored and DevChu committed May 20, 2024
1 parent 3ee32bf commit dabba6a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
5 changes: 3 additions & 2 deletions zk/src/main/resources/web/js/zk/zk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,9 @@ function regClass<S extends typeof ZKObject>(jclass: S): S {
_zk.regClass = regClass;

function defGet(nm: string): Getter {
// eslint-disable-next-line no-new-func
return new Function('return this.' + nm + ';');
return function (this: zk.Widget): unknown {
return this[nm];
};
}
function defSet00(nm: string): GeneratedSetter {
return function (v) {
Expand Down
3 changes: 2 additions & 1 deletion zul/src/main/java/org/zkoss/zul/Datebox.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.zkoss.json.JavaScriptValue;
import org.zkoss.lang.Library;
import org.zkoss.lang.Objects;
import org.zkoss.lang.Strings;
Expand Down Expand Up @@ -1122,7 +1123,7 @@ protected void renderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer) th

String unformater = getUnformater();
if (!Strings.isBlank(unformater))
renderer.render("unformater", unformater);
renderer.render("unformater", new JavaScriptValue(unformater));

if (_locale != null)
renderer.render("localizedSymbols", getRealSymbols(_locale, this));
Expand Down
3 changes: 2 additions & 1 deletion zul/src/main/java/org/zkoss/zul/Timebox.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Map;
import java.util.TimeZone;

import org.zkoss.json.JavaScriptValue;
import org.zkoss.lang.Library;
import org.zkoss.lang.Objects;
import org.zkoss.lang.Strings;
Expand Down Expand Up @@ -336,7 +337,7 @@ protected void renderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer) th

String unformater = getUnformater();
if (!Strings.isBlank(unformater))
renderer.render("unformater", unformater); // TODO: compress
renderer.render("unformater", new JavaScriptValue(unformater)); // TODO: compress

if (_locale != null)
renderer.render("localizedSymbols", getRealSymbols());
Expand Down
8 changes: 4 additions & 4 deletions zul/src/main/resources/web/js/zul/db/Datebox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,12 @@ export class Datebox extends zul.inp.FormatWidget<DateImpl> {
* Sets the unformater function. This method is called from Server side.
* @param unf - the unformater function
*/
setUnformater(unformater: string, opts?: Record<string, boolean>): this {
setUnformater(unformater: zul.db.Unformater, opts?: Record<string, boolean>): this {
const o = this._unformater;
this._unformater = unformater;
this._unformater = unformater.toString();

if (o !== unformater || opts?.force) {
eval('Datebox._unformater = ' + unformater); // eslint-disable-line no-eval
if (o !== this._unformater || opts?.force) {
Datebox._unformater = unformater;
}

return this;
Expand Down
8 changes: 4 additions & 4 deletions zul/src/main/resources/web/js/zul/db/Timebox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ export class Timebox extends zul.inp.FormatWidget<DateImpl> {
* Sets the unformater function. This method is called from Server side.
* @param unformater - the unformater function
*/
setUnformater(unformater: string, opts?: Record<string, boolean>): this {
setUnformater(unformater: zul.db.Unformater, opts?: Record<string, boolean>): this {
const o = this._unformater;
this._unformater = unformater;
this._unformater = unformater.toString();

if (o !== unformater || opts?.force) {
eval('Timebox._unformater = ' + unformater); // eslint-disable-line no-eval
if (o !== this._unformater || opts?.force) {
Timebox._unformater = unformater;
}

return this;
Expand Down

0 comments on commit dabba6a

Please sign in to comment.