Compare commits

..

3 commits

Author SHA1 Message Date
swdee
60c5e24c94
Bug fix: Remove fallback from LCSC barcode part resolver (#1302)
Some checks are pending
Build assets artifact / Build assets artifact (push) Waiting to run
Docker Image Build / build (linux/amd64, amd64, ubuntu-latest) (push) Waiting to run
Docker Image Build / build (linux/arm/v7, armv7, ubuntu-24.04-arm) (push) Waiting to run
Docker Image Build / build (linux/arm64, arm64, ubuntu-24.04-arm) (push) Waiting to run
Docker Image Build / merge (push) Blocked by required conditions
Docker Image Build (FrankenPHP) / build (linux/amd64, amd64, ubuntu-latest) (push) Waiting to run
Docker Image Build (FrankenPHP) / build (linux/arm/v7, armv7, ubuntu-24.04-arm) (push) Waiting to run
Docker Image Build (FrankenPHP) / build (linux/arm64, arm64, ubuntu-24.04-arm) (push) Waiting to run
Docker Image Build (FrankenPHP) / merge (push) Blocked by required conditions
Static analysis / Static analysis (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.2, mysql) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.3, mysql) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.4, mysql) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.5, mysql) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.2, postgres) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.3, postgres) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.4, postgres) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.5, postgres) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.2, sqlite) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.3, sqlite) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.4, sqlite) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.5, sqlite) (push) Waiting to run
2026-03-15 18:57:54 +01:00
Jan Böhmer
de371877b9 Make GenericWebProvider more forgiving with URLs and accept the "fixed" strings traefik provides as security measure
This fixes issue #1296
2026-03-15 18:55:16 +01:00
Jan Böhmer
baeef1228a updated dependencies 2026-03-15 15:06:24 +01:00
6 changed files with 1040 additions and 914 deletions

483
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -2390,6 +2390,9 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
* serialize_payload_fields?: mixed, // Set to null to serialize all payload fields when a validation error is thrown, or set the fields you want to include explicitly. // Default: []
* query_parameter_validation?: bool|Param, // Deprecated: Will be removed in API Platform 5.0. // Default: true
* },
* jsonapi?: array{
* use_iri_as_id?: bool|Param, // Set to false to use entity identifiers instead of IRIs as the "id" field in JSON:API responses. // Default: true
* },
* eager_loading?: bool|array{
* enabled?: bool|Param, // Default: true
* fetch_partial?: bool|Param, // Fetch only partial data according to serialization groups. If enabled, Doctrine ORM entities will not work as expected if any of the other fields are used. // Default: false
@ -2401,11 +2404,12 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
* enable_json_streamer?: bool|Param, // Enable json streamer. // Default: false
* enable_swagger_ui?: bool|Param, // Enable Swagger UI // Default: true
* enable_re_doc?: bool|Param, // Enable ReDoc // Default: true
* enable_scalar?: bool|Param, // Enable Scalar API Reference // Default: true
* enable_entrypoint?: bool|Param, // Enable the entrypoint // Default: true
* enable_docs?: bool|Param, // Enable the docs // Default: true
* enable_profiler?: bool|Param, // Enable the data collector and the WebProfilerBundle integration. // Default: true
* enable_phpdoc_parser?: bool|Param, // Enable resource metadata collector using PHPStan PhpDocParser. // Default: true
* enable_link_security?: bool|Param, // Enable security for Links (sub resources) // Default: false
* enable_link_security?: bool|Param, // Deprecated: This option is always enabled and will be removed in API Platform 5.0. // Enable security for Links (sub resources). // Default: true
* collection?: array{
* exists_parameter_name?: scalar|Param|null, // The name of the query parameter to filter on nullable field values. // Default: "exists"
* order?: scalar|Param|null, // The default order of results. // Default: "ASC"
@ -2505,6 +2509,9 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
* elasticsearch?: bool|array{
* enabled?: bool|Param, // Default: false
* hosts?: list<scalar|Param|null>,
* ssl_ca_bundle?: scalar|Param|null, // Path to the SSL CA bundle file for Elasticsearch SSL verification. // Default: null
* ssl_verification?: bool|Param, // Enable or disable SSL verification for Elasticsearch connections. // Default: true
* client?: "elasticsearch"|"opensearch"|Param, // The search engine client to use: "elasticsearch" or "opensearch". // Default: "elasticsearch"
* },
* openapi?: array{
* contact?: array{
@ -2523,12 +2530,18 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
* identifier?: scalar|Param|null, // An SPDX license expression for the API. The identifier field is mutually exclusive of the url field. // Default: null
* },
* swagger_ui_extra_configuration?: mixed, // To pass extra configuration to Swagger UI, like docExpansion or filter. // Default: []
* scalar_extra_configuration?: mixed, // To pass extra configuration to Scalar API Reference, like theme or darkMode. // Default: []
* overrideResponses?: bool|Param, // Whether API Platform adds automatic responses to the OpenAPI documentation. // Default: true
* error_resource_class?: scalar|Param|null, // The class used to represent errors in the OpenAPI documentation. // Default: null
* validation_error_resource_class?: scalar|Param|null, // The class used to represent validation errors in the OpenAPI documentation. // Default: null
* },
* maker?: bool|array{
* enabled?: bool|Param, // Default: true
* namespace_prefix?: scalar|Param|null, // Add a prefix to all maker generated classes. e.g set it to "Api" to set the maker namespace to "App\Api\" (if the maker.root_namespace config is App). e.g. App\Api\State\MyStateProcessor // Default: ""
* },
* mcp?: bool|array{
* enabled?: bool|Param, // Default: true
* format?: scalar|Param|null, // The serialization format used for MCP tool input/output. Must be a format registered in api_platform.formats (e.g. "jsonld", "json", "jsonapi"). // Default: "jsonld"
* },
* exception_to_status?: array<string, int|Param>,
* formats?: array<string, array{ // Default: {"jsonld":{"mime_types":["application/ld+json"]}}
@ -2613,12 +2626,37 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
* rules?: mixed,
* policy?: mixed,
* middleware?: mixed,
* parameters?: mixed,
* parameters?: array<string, array{ // Default: []
* key?: mixed,
* schema?: mixed,
* open_api?: mixed,
* provider?: mixed,
* filter?: mixed,
* property?: mixed,
* description?: mixed,
* properties?: mixed,
* required?: mixed,
* priority?: mixed,
* hydra?: mixed,
* constraints?: mixed,
* security?: mixed,
* security_message?: mixed,
* extra_properties?: mixed,
* filter_context?: mixed,
* native_type?: mixed,
* cast_to_array?: mixed,
* cast_to_native_type?: mixed,
* cast_fn?: mixed,
* default?: mixed,
* filter_class?: mixed,
* ...<mixed>
* }>,
* strict_query_parameter_validation?: mixed,
* hide_hydra_operation?: mixed,
* json_stream?: mixed,
* extra_properties?: mixed,
* map?: mixed,
* mcp?: mixed,
* route_name?: mixed,
* errors?: mixed,
* read?: mixed,
@ -2626,6 +2664,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
* validate?: mixed,
* write?: mixed,
* serialize?: mixed,
* content_negotiation?: mixed,
* priority?: mixed,
* name?: mixed,
* allow_create?: mixed,

View file

@ -315,7 +315,14 @@ class GenericWebProvider implements InfoProviderInterface
//Remove any leading slashes
$url = ltrim($url, '/');
$url = 'https://'.$url;
//If the URL starts with https:/ or http:/, add the missing slash
//Traefik removes the double slash as secruity measure, so we want to be forgiving and add it back if needed
//See https://github.com/Part-DB/Part-DB-server/issues/1296
if (preg_match('/^https?:\/[^\/]/', $url)) {
$url = preg_replace('/^(https?:)\/([^\/])/', '$1//$2', $url);
} else {
$url = 'https://'.$url;
}
}
//If this is not a valid URL with host, domain and path, throw an exception

View file

@ -217,8 +217,8 @@ final readonly class BarcodeScanResultHandler
* Resolve LCSC barcode -> Part.
* Strategy:
* 1) Try providerReference.provider_id == pc (LCSC "Cxxxxxx") if you store it there
* 2) Fallback to manufacturer_product_number == pm (MPN)
* Returns first match (consistent with EIGP114 logic)
* 2) Fallback to search across supplier part number (SPN)
*/
private function resolvePartFromLCSC(LCSCBarcodeScanResult $barcodeScan): ?Part
{
@ -231,13 +231,8 @@ final readonly class BarcodeScanResultHandler
}
}
// Fallback to MPN (pm)
$pm = $barcodeScan->mpn; // e.g. RC0402FR-071ML
if (!$pm) {
return null;
}
return $this->em->getRepository(Part::class)->getPartByMPN($pm);
// fallback to search by SPN
return $this->em->getRepository(Part::class)->getPartBySPN($pc);
}

View file

@ -115,8 +115,8 @@ final class BarcodeScanResultHandlerTest extends KernelTestCase
public function testLCSCBarcodeResolvePartOrNullReturnsNullWhenNotFound(): void
{
$scan = new LCSCBarcodeScanResult(
fields: ['pc' => 'C0000000', 'pm' => ''],
rawInput: '{pc:C0000000,pm:}'
fields: ['pc' => 'C0000000', 'pm' => 'NON_EXISTENT_MPN_12345'],
rawInput: '{pc:C0000000,pm:NON_EXISTENT_MPN_12345}'
);
$this->assertNull($this->service->resolvePart($scan));

1404
yarn.lock

File diff suppressed because it is too large Load diff