NativeScript / NativeScript/NativeScript

Strange behavior when using TextDecoder

Open
#9,941 2 comments 0 reactions 1 assignee View on GitHub

@triniwiz is already working on this.

Since Jul 27, 2022.

bug
Dominant language
TypeScript
Stars
25.7k
Forks
1.7k
Avg merge
1d 5h
Merged PRs (30d)
35

Description

Issue Description

The textDecoder has strange behavior when working with cbor data.
In node, it is working as expected but in nativescript the TextDecoder returns a strange format:
https://github.com/NativeScript/NativeScript/blob/17c85107ba84953630b0471c1f6f3d68f6d59f76/packages/core/text/text-common.ts#L70

More info:

Issue in node-cbor

Reproduction

https://github.com/abdallahkadour/cbor-node-ns-example

A code snippet will be executed in the app component.

clone and

$ns run ios

It executes the code:

import * as process from "process";
global.process = process;
import * as prereqs from "cbor-rn-prereqs";
import * as cbor from "cbor";

    let object = {
      "1": "DE",
      "6": 1622316073,
      "4": 1643356073,
    };

    console.log(
      "The object ",
      object,
      " Will be encoded and decoded using cbor"
    );

    let encoded = cbor.encode(object);

    console.log("The encode object hex ", encoded.toString("hex"));
    console.log("The encode object ", encoded);

    let decoded = cbor.decode(encoded);
    let decodedString = JSON.stringify(decoded);
    console.log("the decoded string", decodedString);
Relevant log output (if applicable)
The decoded object should be `{
      "1": "DE",
      "6": 1622316073,
      "4": 1643356073,
    };`

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.