Skip to content

[ZEPPELIN-6473] Replace deprecated substr() with slice() in note-create#5305

Open
kimyenac wants to merge 1 commit into
apache:masterfrom
kimyenac:ZEPPELIN-6473
Open

[ZEPPELIN-6473] Replace deprecated substr() with slice() in note-create#5305
kimyenac wants to merge 1 commit into
apache:masterfrom
kimyenac:ZEPPELIN-6473

Conversation

@kimyenac

@kimyenac kimyenac commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

What is this PR for?

The New UI note-create dialog generates note names using String.prototype.substr(), an Annex B (legacy) API the language spec recommends against and flags for eventual removal. This PR migrates the three substr() calls in note-create.component.ts to the recommended slice().

The two methods are not blindly interchangeable — substr(start, length) takes a length, while slice(start, end) takes an end index — so each call site was checked individually to confirm behavior is preserved:

  • newNoteName(): substr(15)slice(15) — single-arg, runs to end of string (equivalent).
  • cloneNoteName(): substr(0, lastIndex)slice(0, lastIndex) — equivalent specifically because the start is 0, so length and the end index coincide.
  • cloneNoteName(): substr(lastIndex)slice(lastIndex) — single-arg, runs to end of string (equivalent).

Generated names for both new notes (Untitled Note N) and cloned notes are unchanged from current behavior.

What type of PR is it?

Improvement

Todos

  • - Replace all three substr() calls with slice()
  • - Confirm no remaining substr() usage in the file

What is the Jira issue?

ZEPPELIN-6473

How should this be tested?

This repository's frontend has no unit-test infrastructure, so verification is via lint plus a production build:

cd zeppelin-web-angular
npm run lint && npm run build:angular

Both pass.

Questions:

  • Does the license files need to update? No
  • Is there breaking changes for older versions? No
  • Does this needs documentation? No

Migrate the three String.prototype.substr() calls in
note-create.component.ts to slice(). substr() is a legacy Annex B API
the spec recommends against. All replacements preserve current behavior:

- newNoteName(): substr(15) -> slice(15) (single-arg, runs to end)
- cloneNoteName(): substr(0, lastIndex) -> slice(0, lastIndex)
  (equivalent because start is 0, so length == end index)
- cloneNoteName(): substr(lastIndex) -> slice(lastIndex) (single-arg)

Verified via npm run lint and npm run build:angular.

@voidmatcha voidmatcha left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The note-create changes look behavior-preserving to me.

One small scope suggestion: although ZEPPELIN-6473 was filed around note-create, if this PR is intended as a New UI substr() cleanup, it may be worth replacing the remaining Angular UI usage as well:

https://github.com/apache/zeppelin/blob/master/zeppelin-web-angular/src/app/services/angular-drag-drop.service.ts#L78

const dotIndex = _callbackStr.indexOf('.');
const callback = dotIndex !== -1 ? _callbackStr.slice(0, dotIndex) : null;

This keeps the existing behavior while avoiding the deprecated substr() call.

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