SShortSingh.
Back to feed

Why Naive String Slicing Breaks Link Previews With Emoji and Urdu Text

0
·1 views

Link preview titles and descriptions are often generated automatically from CMS fields, product feeds, or Markdown bodies rather than written by hand. A common one-line approach that slices strings to a fixed length introduces several bugs. JavaScript's slice counts UTF-16 code units, so it can split emoji such as flags or joined sequences, producing broken characters. The same issue affects Urdu, Arabic, and Hindi text, where combining marks can be detached from their base letters. The article proposes counting grapheme clusters with the built-in Intl.Segmenter, which reflects what readers perceive as single characters. It also offers a tested helper that cuts at word boundaries, falls back to grapheme cuts for overly long tokens, and includes the ellipsis within the length budget.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

Deriving Roof Pitch and Azimuth from Drone Point Clouds Using Python

A drone survey of a roof produces a point cloud of millions of 3D points describing the surface. For solar and roofing work, the key figures are each roof plane's steepness, its facing direction, and its surface area. The approach described uses Python with techniques such as SVD, RANSAC plane fitting, and basic trigonometry to convert raw points into these measurements. The author suggests testing the method on real scans, comparing results against hand measurements, and adjusting thresholds to match the physical roof. Readers are invited to extend the work, for instance with alpha-shape area calculations or obstruction detection.

0
ProgrammingDEV Community ·

Why AI Demos Stall Before Production, and What Teams Must Engineer

Impressive AI demos often take an afternoon to build, but projects can stall for months because a demo tested on a handful of hand-picked examples says little about performance on real cases. Moving to production is mostly ordinary engineering rather than model selection, covering output correctness, integration with software, permission controls, cost tracking, and safe rollout. A central practice is an evaluation set of real inputs with expected correct outputs that can be scored automatically, growing over time as production failures are added. For open-ended outputs, using a second model as a judge can scale evaluation, but it must be calibrated against human labels and its false passes and false fails tracked separately. Structured, schema-validated outputs and specific yes/no rubric questions are also recommended over vague scores or assumed-valid free text.

0
ProgrammingDEV Community ·

How Developers Can Tell Whether Traffic Spikes Signal a Real Data Breach

A common security disclosure phrase says traces of unauthorized access were confirmed, but the article explains how developers can check this themselves. A sudden spike in requests or data egress on a platform like Supabase often stems from internal problems such as buggy client code, heavy unindexed queries, or large unoptimized assets rather than an external attack. Row-Level Security can block unauthenticated reads by returning empty results with a 200 status, so request volume alone does not show data was stolen. The author recommends comparing request counts against egress, reviewing HTTP status codes such as 401, 403, and 429 for signs of automated probing, and checking the network origin of unfamiliar IPs. Together these signals help distinguish harmless internal issues from genuine exposure.

0
ProgrammingDEV Community ·

How Ruby's Method Lookup Really Works Beneath the Object Model

A developer article argues that the common belief that Ruby objects contain their own methods is misleading. Examining CRuby's internals, it notes that an object holds only its instance variables, internal flags, and a pointer to its class. Methods are stored in a method table belonging to the class, which Ruby searches when a method is called. This shared structure keeps memory use efficient, since many instances reuse one table. The piece also explains how defining a method on a single object works, through a hidden eigenclass that Ruby creates behind the scenes.