Skip to content

RegExp for modifyObstructiveCode replaces var names started with top with self when it shouldn't #4794

Closed
@indooorsman

Description

@indooorsman

const topOrParentEqualityBeforeRe = /((?:window|self)(?:\.|\[['"](?:top|self)['"]\])?\s*[!=]==?\s*(?:(?:window|self)(?:\.|\[['"]))?)(top|parent)/g

One of my file contains the below code:

if (topTarget.window === topTarget) { ... }

in Cypress, It's replaced with

if (topTarget.window === selfTarget) { ... }

and it caused error.

Please fix it as soon as possible, many thanks <3

Activity

changed the title [-]The Proxy in Server package has a critical bug when replace `top` to `self`[/-] [+]The Proxy in Server package has a critical bug when replace `top` with `self`[/+] on Jul 24, 2019
jennifer-shehane

jennifer-shehane commented on Jul 24, 2019

@jennifer-shehane
Member

Hey @indooorsman, this is intended behavior in Cypress in order to have sites tested in Cypress work correctly - as they are run from within an iframe - and some sites have framebusting code.

You can turn off this behavior by setting modifyObstructiveCode: false in your configuration.

I'd like to more fully understand the error you are getting and the unintended effect that Cypress seems to have caused in your application though. Can you post the error and explain the unexpected behavior more fully? Thanks.

indooorsman

indooorsman commented on Jul 25, 2019

@indooorsman
Author

@jennifer-shehane Thanks for your reply, the error is selfTarget is not defined.
The original code:

funcA(topTarget) {
  if (topTarget.window === topTarget) { ... }
}

In cypress it's replaced with:

funcA(topTarget) {
  if (topTarget.window === selfTarget) { ... }
}

Of course, selfTarget is not defined.

And I think the regexp topOrParentEqualityBeforeRe has bugs.

About setting modifyObstructiveCode in configuration, it's better to have a default value of false in my opinion.

jennifer-shehane

jennifer-shehane commented on Jul 26, 2019

@jennifer-shehane
Member

@indooorsman Thanks. Yeah, indeed - I agree this RegExp is too lenient in this situation and is definitely a problem. Thanks for clearing this up - we need to fix this.

changed the title [-]The Proxy in Server package has a critical bug when replace `top` with `self`[/-] [+]RegExp for modifyObstructiveCode replaces var names started with `top` with `self` when it shouldn't[/+] on Jul 26, 2019

13 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @jennifer-shehane@indooorsman

    Issue actions

      RegExp for modifyObstructiveCode replaces var names started with `top` with `self` when it shouldn't · Issue #4794 · cypress-io/cypress