Browse Source

Merge pull request #4519 from nocodb/fix/url

fix: fail to identity URL
pull/4536/head
աɨռɢӄաօռɢ 2 years ago committed by GitHub
parent
commit
c1dec6d292
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      packages/nc-gui/package-lock.json
  2. 2
      packages/nc-gui/package.json
  3. 8
      packages/nc-gui/utils/parsers/ExcelTemplateAdapter.ts
  4. 16
      packages/nc-gui/utils/parsers/parserHelpers.ts
  5. 8
      packages/nc-gui/utils/urlUtils.ts

27
packages/nc-gui/package-lock.json generated

@ -32,6 +32,7 @@
"sortablejs": "^1.15.0",
"tinycolor2": "^1.4.2",
"unique-names-generator": "^4.7.1",
"validator": "^13.7.0",
"vue-dompurify-html": "^3.0.0",
"vue-github-button": "^3.0.3",
"vue-i18n": "^9.2.2",
@ -62,6 +63,7 @@
"@types/papaparse": "^5.3.2",
"@types/sortablejs": "^1.13.0",
"@types/tinycolor2": "^1.4.3",
"@types/validator": "^13.7.10",
"@vitest/ui": "^0.18.0",
"@vue/compiler-sfc": "^3.2.37",
"@vue/test-utils": "^2.0.2",
@ -3099,6 +3101,12 @@
"integrity": "sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==",
"dev": true
},
"node_modules/@types/validator": {
"version": "13.7.10",
"resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.7.10.tgz",
"integrity": "sha512-t1yxFAR2n0+VO6hd/FJ9F2uezAZVWHLmpmlJzm1eX03+H7+HsuTAp7L8QJs+2pQCfWkP1+EXsGK9Z9v7o/qPVQ==",
"dev": true
},
"node_modules/@types/web-bluetooth": {
"version": "0.0.15",
"resolved": "https://registry.npmjs.org/@types/web-bluetooth/-/web-bluetooth-0.0.15.tgz",
@ -15866,6 +15874,14 @@
"spdx-expression-parse": "^3.0.0"
}
},
"node_modules/validator": {
"version": "13.7.0",
"resolved": "https://registry.npmjs.org/validator/-/validator-13.7.0.tgz",
"integrity": "sha512-nYXQLCBkpJ8X6ltALua9dRrZDHVYxjJ1wgskNt1lH9fzGjs3tgojGSCBjmEPwkWS1y29+DrizMTW19Pr9uB2nw==",
"engines": {
"node": ">= 0.10"
}
},
"node_modules/vite": {
"version": "2.9.15",
"resolved": "https://registry.npmjs.org/vite/-/vite-2.9.15.tgz",
@ -19583,6 +19599,12 @@
"integrity": "sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==",
"dev": true
},
"@types/validator": {
"version": "13.7.10",
"resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.7.10.tgz",
"integrity": "sha512-t1yxFAR2n0+VO6hd/FJ9F2uezAZVWHLmpmlJzm1eX03+H7+HsuTAp7L8QJs+2pQCfWkP1+EXsGK9Z9v7o/qPVQ==",
"dev": true
},
"@types/web-bluetooth": {
"version": "0.0.15",
"resolved": "https://registry.npmjs.org/@types/web-bluetooth/-/web-bluetooth-0.0.15.tgz",
@ -28918,6 +28940,11 @@
"spdx-expression-parse": "^3.0.0"
}
},
"validator": {
"version": "13.7.0",
"resolved": "https://registry.npmjs.org/validator/-/validator-13.7.0.tgz",
"integrity": "sha512-nYXQLCBkpJ8X6ltALua9dRrZDHVYxjJ1wgskNt1lH9fzGjs3tgojGSCBjmEPwkWS1y29+DrizMTW19Pr9uB2nw=="
},
"vite": {
"version": "2.9.15",
"resolved": "https://registry.npmjs.org/vite/-/vite-2.9.15.tgz",

2
packages/nc-gui/package.json

@ -55,6 +55,7 @@
"sortablejs": "^1.15.0",
"tinycolor2": "^1.4.2",
"unique-names-generator": "^4.7.1",
"validator": "^13.7.0",
"vue-dompurify-html": "^3.0.0",
"vue-github-button": "^3.0.3",
"vue-i18n": "^9.2.2",
@ -85,6 +86,7 @@
"@types/papaparse": "^5.3.2",
"@types/sortablejs": "^1.13.0",
"@types/tinycolor2": "^1.4.3",
"@types/validator": "^13.7.10",
"@vitest/ui": "^0.18.0",
"@vue/compiler-sfc": "^3.2.37",
"@vue/test-utils": "^2.0.2",

8
packages/nc-gui/utils/parsers/ExcelTemplateAdapter.ts

@ -132,15 +132,15 @@ export default class ExcelTemplateAdapter extends TemplateGenerator {
if (column.uidt === UITypes.SingleLineText) {
// check for long text
if (isMultiLineTextType(rows)) {
if (isMultiLineTextType(rows, col)) {
column.uidt = UITypes.LongText
}
if (isEmailType(rows)) {
if (isEmailType(rows, col)) {
column.uidt = UITypes.Email
}
if (isUrlType(rows)) {
if (isUrlType(rows, col)) {
column.uidt = UITypes.URL
} else {
const vals = rows
@ -148,7 +148,7 @@ export default class ExcelTemplateAdapter extends TemplateGenerator {
.map((r: any) => r[col])
.filter((v: any) => v !== null && v !== undefined && v.toString().trim() !== '')
const checkboxType = isCheckboxType(vals)
const checkboxType = isCheckboxType(vals, col)
if (checkboxType.length === 1) {
column.uidt = UITypes.Checkbox
} else {

16
packages/nc-gui/utils/parsers/parserHelpers.ts

@ -20,11 +20,11 @@ const booleanOptions = [
]
const aggBooleanOptions: any = booleanOptions.reduce((obj, o) => ({ ...obj, ...o }), {})
const getColVal = (row: any, col = null) => {
const getColVal = (row: any, col?: number) => {
return row && col ? row[col] : row
}
export const isCheckboxType: any = (values: [], col = null) => {
export const isCheckboxType: any = (values: [], col?: number) => {
let options = booleanOptions
for (let i = 0; i < values.length; i++) {
const val = getColVal(values[i], col)
@ -45,7 +45,7 @@ export const getCheckboxValue = (value: any) => {
return value && aggBooleanOptions[value]
}
export const isMultiLineTextType = (values: [], col = null) => {
export const isMultiLineTextType = (values: [], col?: number) => {
return values.some(
(r) => (getColVal(r, col) || '').toString().match(/[\r\n]/) || (getColVal(r, col) || '').toString().length > 255,
)
@ -107,13 +107,15 @@ export const isDecimalType = (colData: []) =>
return v && parseInt(v) !== +v
})
export const isEmailType = (colData: []) =>
colData.some((v: any) => {
export const isEmailType = (colData: [], col?: number) =>
colData.some((r: any) => {
const v = getColVal(r, col)
return v && validateEmail(v)
})
export const isUrlType = (colData: []) =>
colData.some((v: any) => {
export const isUrlType = (colData: [], col?: number) =>
colData.some((r: any) => {
const v = getColVal(r, col)
return v && isValidURL(v)
})

8
packages/nc-gui/utils/urlUtils.ts

@ -1,3 +1,5 @@
import isURL from 'validator/lib/isURL'
export const replaceUrlsWithLink = (text: string): boolean | string => {
if (!text) {
return false
@ -17,12 +19,8 @@ export const replaceUrlsWithLink = (text: string): boolean | string => {
return found && out
}
// ref : https://stackoverflow.com/a/5717133
export const isValidURL = (str: string) => {
const pattern =
/^(?:(?:https?|ftp):\/\/)?(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00A1-\uFFFF0-9]-*)*[a-z\u00A1-\uFFFF0-9]+)(?:\.(?:[a-z\u00A1-\uFFFF0-9]-*)*[a-z\u00A1-\uFFFF0-9]+)*(?:\.(?:[a-z\u00A1-\uFFFF]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?$/i
return pattern.test(str)
return isURL(str)
}
export const openLink = (path: string, baseURL?: string, target = '_blank') => {

Loading…
Cancel
Save