mirror of
https://github.com/maputnik/editor.git
synced 2026-08-24 14:07:33 +00:00
Merge ab1e6ffd8f into b429bb16d7
This commit is contained in:
+14
-10
@@ -10,16 +10,19 @@ function validate(url: string, t: TFunction): JSX.Element | undefined {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let error;
|
let error;
|
||||||
const getProtocol = (url: string) => {
|
const getUrlParams = (url: string) => {
|
||||||
try {
|
try {
|
||||||
const urlObj = new URL(url);
|
const urlObj = new URL(url);
|
||||||
return urlObj.protocol;
|
const { protocol, hostname } = urlObj;
|
||||||
}
|
// Basic check against localhost; 127.0.0.1/8 and IPv6 localhost [::1]
|
||||||
catch (err) {
|
const isLocal = /^(localhost|\[::1\]|127(.[0-9]{1,3}){3})/i.test(hostname);
|
||||||
return undefined;
|
|
||||||
|
return { protocol, isLocal };
|
||||||
|
} catch (err) {
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const protocol = getProtocol(url);
|
const { protocol, isLocal } = getUrlParams(url);
|
||||||
const isSsl = window.location.protocol === "https:";
|
const isSsl = window.location.protocol === "https:";
|
||||||
|
|
||||||
if (!protocol) {
|
if (!protocol) {
|
||||||
@@ -40,7 +43,8 @@ function validate(url: string, t: TFunction): JSX.Element | undefined {
|
|||||||
else if (
|
else if (
|
||||||
protocol &&
|
protocol &&
|
||||||
protocol === "http:" &&
|
protocol === "http:" &&
|
||||||
window.location.protocol === "https:"
|
window.location.protocol === "https:" &&
|
||||||
|
!isLocal
|
||||||
) {
|
) {
|
||||||
error = (
|
error = (
|
||||||
<SmallError>
|
<SmallError>
|
||||||
@@ -76,10 +80,10 @@ type FieldUrlState = {
|
|||||||
|
|
||||||
class FieldUrlInternal extends React.Component<FieldUrlInternalProps, FieldUrlState> {
|
class FieldUrlInternal extends React.Component<FieldUrlInternalProps, FieldUrlState> {
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
onInput: () => {},
|
onInput: () => { },
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor (props: FieldUrlInternalProps) {
|
constructor(props: FieldUrlInternalProps) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
error: validate(props.value, props.t),
|
error: validate(props.value, props.t),
|
||||||
@@ -100,7 +104,7 @@ class FieldUrlInternal extends React.Component<FieldUrlInternalProps, FieldUrlSt
|
|||||||
this.props.onChange(url);
|
this.props.onChange(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<InputString
|
<InputString
|
||||||
|
|||||||
Reference in New Issue
Block a user