Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HighlightPipe doesn't supports sanitized values #432

Open
GreenToast opened this issue Sep 22, 2016 · 7 comments
Open

HighlightPipe doesn't supports sanitized values #432

GreenToast opened this issue Sep 22, 2016 · 7 comments

Comments

@GreenToast
Copy link

GreenToast commented Sep 22, 2016

Hi I migrated today to v.1.1.0 and adapted all params. I got problems with the text-selection. When I typed in one letter in the ng-select-component I got this error

TypeError: value.match is not a function at HighlightPipe.transform (select-pipes.js:15)

It seems that the function receives a sanitized value and not a pure value. So by adding one line to check the value if it is sanitized or not solves the problem.

HighlightPipe.prototype.transform = function (_value, args) {

       //this line fixes the problem
        var value =  _value.changingThisBreaksApplicationSecurity ? value.changingThisBreaksApplicationSecurity:_value;

        if (args.length < 1) {
            return value;
        }
        var query = args[0];
        if (query) {
            var tagRE = new RegExp('<[^<>]*>', 'ig');
            // get ist of tags
            var tagList = value.match(tagRE);

I hope you can fix it soon. It blocks our migration to 1.1.0.

@alpeshv
Copy link

alpeshv commented Sep 23, 2016

Same as #437 #438

@Scipionh
Copy link

As this major bug is present in the only version supporting Angular2, fixing it soon would be really appreciated.

@GuillaumeDK57
Copy link

+1

@moodyroto
Copy link

To follow up with @GreenToast's recommendation, if anyone is looking for a hotfix, you can drop this into your main.ts file:

import {escapeRegexp} from 'ng2-select/components/select/common';
import {HighlightPipe} from 'ng2-select/components/select/select-pipes';

HighlightPipe.prototype.transform = (value: any, args: any[]) => {
    if (args.length < 1) {
        return value;
    }

    let query = args[0];

    if ( query ) {
        value = value.changingThisBreaksApplicationSecurity || value;

        let tagRE    = new RegExp('<[^<>]*>', 'ig');

        // get ist of tags
        let tagList  = value.match( tagRE );

        // Replace tags with token
        let tmpValue = value.replace( tagRE, '$!$');

        // Replace search words
        value = tmpValue.replace(
            new RegExp(escapeRegexp(query), 'gi'),
            '<strong>$&</strong>'
        );

        // Reinsert HTML
        for (let i = 0; value.indexOf('$!$') > -1; i++) {
            value = value.replace('$!$', tagList[i]);
        }
    }

    return value;
};

@monica11
Copy link

+1 @Scipionh

@gauzpan
Copy link

gauzpan commented Sep 30, 2016

@moodyroto Nice workaround. It worked for me.
@valorkin Hope this issue might be addressed in the package also sometime later.

@vixriihi
Copy link
Contributor

Are you getting HighlightPipe.prototype.transform = (value: any, args: any[]) => { args parameter as an array? For me it was a string and so it ended up highlighting only the first character. I created a PR (#454) that fixed this issue in here.

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

No branches or pull requests

8 participants