mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-12 19:34:31 +02:00
Strip HTML tags from more LCSC fields
This should hopefully fix issue #553
This commit is contained in:
parent
a5b101a0ea
commit
59c4248efe
1 changed files with 23 additions and 7 deletions
|
@ -128,6 +128,21 @@ class LCSCProvider implements InfoProviderInterface
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sanitizes a field by removing any HTML tags and other unwanted characters
|
||||||
|
* @param string|null $field
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
private function sanitizeField(?string $field): ?string
|
||||||
|
{
|
||||||
|
if ($field === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return strip_tags($field);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes a deserialized json object of the product and returns a PartDetailDTO
|
* Takes a deserialized json object of the product and returns a PartDetailDTO
|
||||||
* @param array $product
|
* @param array $product
|
||||||
|
@ -146,8 +161,9 @@ class LCSCProvider implements InfoProviderInterface
|
||||||
|
|
||||||
// LCSC puts HTML in footprints and descriptions sometimes randomly
|
// LCSC puts HTML in footprints and descriptions sometimes randomly
|
||||||
$footprint = $product["encapStandard"] ?? null;
|
$footprint = $product["encapStandard"] ?? null;
|
||||||
if ($footprint !== null) {
|
//If the footprint just consists of a dash, we'll assume it's empty
|
||||||
$footprint = strip_tags($footprint);
|
if ($footprint === '-') {
|
||||||
|
$footprint = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Build category by concatenating the catalogName and parentCatalogName
|
//Build category by concatenating the catalogName and parentCatalogName
|
||||||
|
@ -163,14 +179,14 @@ class LCSCProvider implements InfoProviderInterface
|
||||||
provider_key: $this->getProviderKey(),
|
provider_key: $this->getProviderKey(),
|
||||||
provider_id: $product['productCode'],
|
provider_id: $product['productCode'],
|
||||||
name: $product['productModel'],
|
name: $product['productModel'],
|
||||||
description: strip_tags($product['productIntroEn']),
|
description: $this->sanitizeField($product['productIntroEn']),
|
||||||
category: $category,
|
category: $this->sanitizeField($category ?? null),
|
||||||
manufacturer: $product['brandNameEn'],
|
manufacturer: $this->sanitizeField($product['brandNameEn'] ?? null),
|
||||||
mpn: $product['productModel'] ?? null,
|
mpn: $this->sanitizeField($product['productModel'] ?? null),
|
||||||
preview_image_url: $product['productImageUrl'],
|
preview_image_url: $product['productImageUrl'],
|
||||||
manufacturing_status: null,
|
manufacturing_status: null,
|
||||||
provider_url: $this->getProductShortURL($product['productCode']),
|
provider_url: $this->getProductShortURL($product['productCode']),
|
||||||
footprint: $footprint,
|
footprint: $this->sanitizeField($footprint),
|
||||||
datasheets: $this->getProductDatasheets($product['pdfUrl'] ?? null),
|
datasheets: $this->getProductDatasheets($product['pdfUrl'] ?? null),
|
||||||
images: $product_images,
|
images: $product_images,
|
||||||
parameters: $this->attributesToParameters($product['paramVOList'] ?? []),
|
parameters: $this->attributesToParameters($product['paramVOList'] ?? []),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue