Skip to content

Commit

Permalink
fix(json-schema): do not send invalid URLs (#9417)
Browse files Browse the repository at this point in the history
  • Loading branch information
anshbansal authored Dec 12, 2023
1 parent ee4e8dd commit abbc4cd
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from os.path import basename, dirname
from pathlib import Path
from typing import Any, Iterable, List, Optional, Union
from urllib.parse import urlparse

import jsonref
from pydantic import AnyHttpUrl, DirectoryPath, FilePath, validator
Expand Down Expand Up @@ -53,6 +54,16 @@
logger = logging.getLogger(__name__)


def is_url_valid(url: Optional[str]) -> bool:
if url is None:
return False
try:
result = urlparse(url)
return all([result.scheme, result.netloc])
except Exception:
return False


class URIReplacePattern(ConfigModel):
match: str = Field(
description="Pattern to match on uri-s as part of reference resolution. See replace field",
Expand Down Expand Up @@ -281,12 +292,14 @@ def _load_one_file(
entityUrn=dataset_urn, aspect=models.StatusClass(removed=False)
).as_workunit()

external_url = JsonSchemaTranslator._get_id_from_any_schema(schema_dict)
if not is_url_valid(external_url):
external_url = None

yield MetadataChangeProposalWrapper(
entityUrn=dataset_urn,
aspect=models.DatasetPropertiesClass(
externalUrl=JsonSchemaTranslator._get_id_from_any_schema(
schema_dict
),
externalUrl=external_url,
name=dataset_simple_name,
description=JsonSchemaTranslator._get_description_from_any_schema(
schema_dict
Expand Down

0 comments on commit abbc4cd

Please sign in to comment.