Skip to content

Commit

Permalink
fix: fix issue with CSV separator in contents (#1460)
Browse files Browse the repository at this point in the history
  • Loading branch information
meteyou authored Jul 16, 2023
1 parent 7c81690 commit 1895d2d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/components/mixins/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ export default class BaseMixin extends Vue {
}

get browserLocale() {
return navigator.languages && navigator.languages.length ? navigator.languages[0] : navigator.language
return navigator.language
}

get hours12Format() {
const setting = this.$store.state.gui.general.timeFormat
if (setting === '12hours') return true
if (setting === null && this.browserLocale === 'en_us') return true
if (setting === null && this.browserLocale === 'en-US') return true

return false
}
Expand Down
13 changes: 10 additions & 3 deletions src/components/panels/HistoryListPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ export default class HistoryListPanel extends Mixins(BaseMixin) {
}
exportHistory() {
const checkString = parseFloat('1.23').toLocaleString()
const checkString = parseFloat('1.23').toLocaleString(this.browserLocale)
const decimalSeparator = checkString.indexOf(',') >= 0 ? ',' : '.'
const csvSeperator = decimalSeparator === ',' ? ';' : ','
Expand Down Expand Up @@ -1011,7 +1011,14 @@ export default class HistoryListPanel extends Mixins(BaseMixin) {
})
}
const csvContent = 'data:text/csv;charset=utf-8,' + content.map((e) => e.join(csvSeperator)).join('\n')
// escape fields with the csvSeperator in the content
// prettier-ignore
const csvContent =
'data:text/csv;charset=utf-8,' +
content.map((entry) =>
entry.map((field) => (field.indexOf(csvSeperator) === -1 ? field : `"${field}"`)).join(csvSeperator)
).join('\n')
const link = document.createElement('a')
link.setAttribute('href', encodeURI(csvContent))
link.setAttribute('download', 'print_history.csv')
Expand Down Expand Up @@ -1044,7 +1051,7 @@ export default class HistoryListPanel extends Mixins(BaseMixin) {
default:
switch (typeof value) {
case 'number':
return value?.toLocaleString(undefined, { useGrouping: false }) ?? 0
return value?.toLocaleString(this.browserLocale, { useGrouping: false }) ?? 0
case 'string':
if (escapeChar !== null && value.includes(escapeChar)) value = '"' + value + '"'
Expand Down

0 comments on commit 1895d2d

Please sign in to comment.