Search SMS Text Literally When Pattern Characters Are Present

Published: · Updated:
Share

A search for a percent sign or underscore can match unexpected SMS records if the application interprets it as a pattern. A no SIM online SMS inbox should define whether the input means literal text or a supported query language. The user should not have to infer that meaning from surprising totals.

Parameter binding and pattern meaning differ

A parameterised query separates data from SQL structure, but an operator such as LIKE can still interpret pattern characters within the supplied value. PostgreSQL documents its own matching rules. Use the actual database and endpoint contract rather than treating every escaping function as interchangeable.

SQL parameter handling, pattern escaping and safe HTML output are different boundaries. A replacement intended for one context should not become the universal treatment for all search input. That can damage source text while leaving the actual matching behaviour unclear.

Do not tell a user to remove meaningful characters until a search returns something. The expected behaviour should come from the product’s documented mode, not from guessing which punctuation its implementation happens to treat specially.

A search has different interpretation boundaries

Choose the intended product behaviour

If the field promises to find original text, construct the supported literal query on the server. Where wildcards or regular expressions are deliberately available, make the mode and restrictions explicit. Normal input should not unexpectedly trigger an expensive expression.

Different searchable fields can also have different contracts. Recipient identifiers, sender values and bodies need not use the same comparison rules. Define them clearly enough that a zero match or broad match can be explained.

Keep resource and date scope with the query. Even correct literal matching does not establish that every historical record was searched. The result should describe the actual filter and completion state.

Make highlighting agree with lookup

A literal server query followed by unescaped regular-expression highlighting can produce another mismatch. Highlighting must also keep the original body as untrusted text rather than turning it into HTML.

Exports should retain the effective query scope, not merely copy the text box label as if it described the complete operation. Where a mode exists, include its meaning with the result used by another authorised operator.

Case comparison and text normalisation are additional choices. A literal mode still needs a documented rule about those behaviours if they affect results. Do not silently rewrite a verification string or identifier merely to make a search match. Where a field requires exact characters, keep that requirement distinct from a convenience search intended for ordinary prose.

Fixtures distinguish search modes

Test characters that distinguish the modes

Use harmless records containing a percent sign, underscore, ordinary letters and empty fields. Define expected literal and supported-pattern matches separately. Include length limits, invalid patterns and bounded query cost under the chosen design.

Do not submit active codes or private message content to an unrelated online expression tester. Fictional strings can reproduce the same parsing and matching distinctions without disclosing account material.

Retain the database, operator and product promise in the maintenance record. Verify the assembled search and display path rather than only whether a query stops producing syntax errors. The closing result is that the input’s intended meaning, the matched objects and the highlighted text remain consistent across normal and special-character cases.

Reference: PostgreSQL: pattern matching.

Need help?

Click here and start chatting with us!