Skip to content

fix validation lengths per schema - #1001

Merged
timschofield merged 1 commit into
timschofield:masterfrom
dalers:fixlengths
Sep 1, 2026
Merged

fix validation lengths per schema#1001
timschofield merged 1 commit into
timschofield:masterfrom
dalers:fixlengths

Conversation

@dalers

@dalers dalers commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Attempted to edit imported product and the validation test for the description failed because it was (still) 50 characters.

Requested Copilot verify validation tests vs schema and implemented recommended changes.

Data validation conflicts in Stocks.php vs. stockmaster schema

Field Code validation Schema definition Conflict
Description Stocks.php:145: rejects if mb_strlen() > 50; HTML maxlength="50" (Stocks.php:1003) varchar(255) Overly restrictive — valid descriptions up to 255 chars (allowed by the schema) are rejected by a hard-coded 50-char limit.
BarCode Stocks.php:176: rejects if mb_strlen() > 20, error message says "20 characters"; HTML maxlength="20" (Stocks.php:1305) varchar(50) Overly restrictive — legitimate barcodes of 21–50 chars (valid per schema, e.g. GS1-128/EAN longer formats) are rejected.
StockID Stocks.php:157-168: only checks non-empty and ContainsIllegalCharacters(); no max-length check in PHP. HTML maxlength="20" (Stocks.php:918) is the only length limit, and it's client-side only varchar(64) Under-validated — server-side code never enforces the 64-char schema limit, and the only limit that exists (HTML maxlength=20) is far short of what the schema permits and easily bypassed (direct POST). A submitted StockID between 21–64 chars would be silently rejected by the UI, while one > 64 chars sent directly would hit the DB with no PHP-side check.

Other fields checked and found consistent (no conflict):

  • Units — code limits to 20 chars, matches units varchar(20).
  • DiscountCategory — HTML maxlength="2" matches char(2).
  • CategoryID/TaxCat — populated from <select> lists sourced directly from stockcategory/taxcategories, so values are inherently constrained by the FK relationship.
  • EOQ, Volume, GrossWeight, NetWeight, Pansize, ShrinkFactor — only numeric/positive checks are needed since the schema columns are double/decimal, and that's what's tested.

Recommended fix: relax the Description (50→255) and BarCode (20→50) length checks (and their HTML maxlength/error text) to match the schema, and add an explicit mb_strlen($StockID) > 64 check (with matching HTML maxlength="64") so the PHP validation actually enforces the schema's stockid varchar(64) limit.

@timschofield
timschofield merged commit 46b6902 into timschofield:master Sep 1, 2026
4 checks passed
@dalers
dalers deleted the fixlengths branch September 1, 2026 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants