Skip to content

Commit

Permalink
BUGFIX: enables updating character varying []
Browse files Browse the repository at this point in the history
  • Loading branch information
jzwood authored and Paxa committed Mar 25, 2022
1 parent 252cae2 commit cef04f3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
13 changes: 7 additions & 6 deletions app/view_cell_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ declare global {
timeFormat: (date: string) => string
execTime: (time: number) => string
formatJson: (value: any) => string
formatJsonArray: (value: any) => string
formatArray: (value: any, format: string) => string
getIndexType: (indexSql: string) => string
escapeHTML: (unsafe: string) => string
Expand Down Expand Up @@ -116,11 +115,13 @@ var helpers = global.ViewCellHelpers = {
break;
}

if (dataType == 'ARRAY' && Array.isArray(value)) {
formated = this.formatArray(value, format);
} else if (['json[]', 'jsonb[]'].includes(dataType) && Array.isArray(value)) {
formated = this.formatJsonArray(value);
htmlEscaped = true;
if (Array.isArray(value)) {
if (dataType == 'ARRAY') {
formated = this.formatArray(value, format);
} else {
formated = this.formatJson(value);
htmlEscaped = true
}
}

if (!htmlEscaped && typeof formated == 'string') {
Expand Down
1 change: 0 additions & 1 deletion app/view_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ declare global {
timeFormat: (date: string) => string
execTime: (time: number) => string
formatJson: (value: any) => string
formatJsonArray: (value: any) => string
formatArray: (value: any, format: string) => string
getIndexType: (indexSql: string) => string
escapeHTML: (unsafe: string) => string
Expand Down
8 changes: 5 additions & 3 deletions app/views/panes/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,11 +616,13 @@ class Content extends PaneBase {
//global.editValue = value;

const sanitizeUpdateValue = (dataType, stringValue) => {
if (['json[]', 'jsonb[]'].includes(dataType)) {
const bracket = (v) => "{" + v + "}"
const quote = (v) => "\"" + v + "\""
const bracket = (v) => "{" + v + "}"
const quote = (v) => "\"" + v + "\""
if (/^jsonb?\[\]$/.test(dataType)) {
const jsonArray = JSON.parse(stringValue)
return bracket(jsonArray.map(json => quote(JSON.stringify(json).replace(/"/g, '\\"'))).toString())
} else if (/^character varying\(\d+\)\[\]$/.test(dataType)) {
return bracket(JSON.parse(stringValue).toString())
}
return stringValue
}
Expand Down
2 changes: 1 addition & 1 deletion views/dialogs/edit_value.jade
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ form
option(value="true" selected=value) true
option(value="false" selected=(value === false) ) false
else
if ["json", "jsonb"].includes(fieldType.udt_name) || (["json[]", "jsonb[]"].includes(fieldType.data_type) && Array.isArray(value))
if ["json", "jsonb"].includes(fieldType.udt_name) || (fieldType.data_type.includes("[]") && Array.isArray(value))
- value = JSON.stringify(value, null, 2)
textarea(name="value" placeholder=fieldType.column_default disabled=valueIsNull)= value

Expand Down

0 comments on commit cef04f3

Please sign in to comment.