Skip to content

Bug in URI.isUri() that fails thing type comparison #114971

Closed

Description

@enagic
  • VSCode Version: 1.53.0
  • OS Version: macOS 11.1

Steps to Reproduce:

  1. Create custom URI class that implements the default URI
  2. Pass in the custom URI into URI.isUri(myCustomUri) and it returns false

Background

This is a proposed fix for monaco-editor.

If a model is created using a custom URI, it will fail the URI.isUri() check because it "tries" to check thing against various possible types, but it will fail at fsPath.

class URI {
    static isUri(thing) {
        if (thing instanceof URI) {
            return true;
        }
        if (!thing) {
            return false;
        }
        return typeof thing.authority === 'string'
            && typeof thing.fragment === 'string'
            && typeof thing.path === 'string'
            && typeof thing.query === 'string'
            && typeof thing.scheme === 'string'
            && typeof thing.fsPath === 'function' // this guy right here should be 'string'
            && typeof thing.with === 'function'
            && typeof thing.toString === 'function';
    }
}

The side-effect is that markerService behaves a bit weird and shows markers for all resources, not just for a particular resource/URI.

Example:

class MyUri implements Uri {
  ...
  // rest of class to satisfy TS
  ...
}

const myUri = MyUri.parse('foo://example.com:8042/over/there');

// Note:
// - myUri is _not_ an instanceof Uri
// - typeof myUri.fsPath === 'string', not 'function'

const model = editor.createModel('', 'plaintext', myUri);
const { resource } = model;

// `resourceMarkers` ends up returning all markers of `markerService._data`,
// not just the resource's markers because `DataResourceMap.values()`
// fails the `URI.isUri()` check.
const resourceMarkers = markerService.read({ resource });

Does this issue occur when all extensions are disabled?: Yes

Activity

  1. added
    bug
    on Jan 26, 2021
  2. jrieken commented on Jan 26, 2021

    @jrieken
    Contributor

    Indeed. Nice find.

  3. added
    unreleased
    on Jan 26, 2021
  4. added
    insiders-released
    and removed
    unreleased
    on Jan 27, 2021
  5. locked and limited conversation to collaborators on Mar 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

buginsiders-releaseduriverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions