Urgent.News

What's breaking now, across thousands of outlets.

Tech

You Filled the Email Template With replace and the Second {name} Went Out Unfilled

The template was simple. A renewal reminder, written by marketing, with two places for the name. Hi {name}, at the top. We will keep everything ready for you, {name}, near the bottom. The code that filled it was one line per field. body = body.replace("{name}", customer.firstName); The test used a template with one {name} in it. It passed. Then the new copy went out to eleven thousand customers,…

The email template was straightforward, containing two spaces where a person's name should have appeared. At the beginning, it read "Hi {name}," and at the end, the message concluded with "{name},". The code responsible for inserting the names was simple, using the replace method to fill in the placeholders with the customer's first name.

Initially, the test with a template having one {name} passed successfully. However, when the code was deployed to eleven thousand customers, every single one received an email with only the first name filled in, leaving the second space unfilled. The issue lies in JavaScript's replace function, which only replaces the first occurrence of the string, not all instances.

This behavior, while documented, is not universally understood. To rectify this, two options were presented: utilizing replaceAll for JavaScript, which replaces every occurrence, or employing a regular expression with the 'g' flag. However, these solutions come with their own complexities. Additionally, the use of a replacement function allows for more control over the inserted text, preventing unintended alterations.

Ultimately, the best approach would be to move away from using replace for this purpose and instead adopt a template engine that handles placeholders explicitly. Moreover, a pre-send check to ensure there are no remaining placeholders would further guarantee the integrity of the emails sent out.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

HertzBeat's default accounts turn monitoring access into an operational risk

HertzBeat's default accounts turn monitoring access into an operational risk Monitoring systems collect topology, availability, and often credentials for the endpoints they check.

  • HertzBeat default accounts create operational risk by increasing monitoring system vulnerability.
  • Default admin account with password "hertzbeat" can grant excessive access if not properly managed.
  • Monitoring system's extensive reach and weak login credentials pose significant pivot point risk.

# Meshy T2: Native 3D Mesh Generation with Flow Matching

Adapted from Rendong Liang’s article on the Meshy blog . When you evaluate a generated 3D asset, the preview image answers only part of the question. What does the wireframe look like? Are separate components still separate? Can the geometry fit your application’s budget?

  • Meshy T2 generates 3D mesh geometry directly without stitching processes.
  • Uses two flow-matching stages: voxel flow and mesh flow.
  • Generates disconnected components within a single asset.

skif: replacing sherif, syncpack and most of knip with one Rust binary

I was working on restructuring a very large monorepo with disparate package managers and versions into a single PNPM workspace. When I was finished I decided I am going to enforce certain conventions so it could not drift again without failing CI.

  • Skif is a Rust-based linter consolidating Sherif, Syncpack, and Knip functionality
  • Supports npm, pnpm, Yarn, Bun, Rush, and Lerna package managers
  • Achieves 32ms median runtime, matches Sherif/Syncpack accuracy

More from Monday 9 November →