coston / react-obfuscate Goto Github PK
View Code? Open in Web Editor NEWAn intelligent React component to obfuscate any contact link!
Home Page: https://react-obfuscate.coston.io
License: MIT License
An intelligent React component to obfuscate any contact link!
Home Page: https://react-obfuscate.coston.io
License: MIT License
Email addresses containing dashes are still reversed for me similar to #30
This bug appears for me on recent versions of both Chrome and Firefox.
Things I've tried:
style={{display:'inline-block'}}
on the elementstyle={{ unicodeBidi: 'isolate-overide'}}
which was mentioned in #29style={{ display:'inline-block', unicodeBidi: 'bidi-overide'}}
For context, I'm using the Obfuscate element within an html table. It's the only element within the table cell, and I am not using consecutive inline elements inside a block element.
Oddly enough, each reversed email (the ones containing dashes) also appears visually with a line break before/after the breakpoint.
It would be useful to override the rendered component to allow using (for instance) a <span />
. Something like:
<Obfuscate component="span" skipHref>whatever</Obfuscate>
could render as:
<span style="unicode-bidi: isolate-override; direction: rtl;">revetahw</span>
<Obfuscate tel="(347) 855 6622" />
renders as
)347( 855 6622
is this expected behavior?
Suggested feature:
Sometimes, I turn a person's name into a link to their email. It would be nice to have a property to not obfuscate the children.
<Obfuscate email={staff.email} obfuscateChildren={false}>{staff.name}</Obfuscate>
Hi @coston, thank you for putting out this component! I was wondering if you've considered adding an option to specify the render component to be a custom component?
In my particular case, I already have a custom styled Link component that I rather that this is uses, and I imagine might be the case for others as well.
Describe the bug
onClick
(props.onClick
) is called only if this.state.humanInteraction === false
. If the cursor has entered the link area, this.state.humanInteraction === true
, so the passed onClick
prop function is not called.
See handleCopiability and handleClick methods (code below).
Happy to make a PR if you agree this is an issue.
Otherwise, what am I missing?
To Reproduce
<Obfuscate />
a custom onClick
method eg<Obfuscate onClick={() => console.log('test'} />
<Obfuscate />
will descramble the link, but the onClick
method does not get called.Expected behavior
When user clicks, the onClick
prop will be called before the deobfuscation method(s), as implied in docs.
Relevant lines
handleClick(event) {
const { onClick } = this.props
// If focused or hovered, this js will be skipped with preference for html
if (this.state.humanInteraction === false) { // <--- 1. THIS IS NOT SATISFIED AFTER USER HOVER
event.preventDefault()
// Allow instantiator to provide an onClick method to be called
// before we change location (e.g. for analytics tracking)
if (onClick && typeof onClick === 'function') {
onClick() // <--- 2. SO THIS IS NOT CALLED
}
window.location.href = this.createContactLink(this.props)
}
}
Hi,
when I upgraded your package to the latest version, I suddenly started seeing a visual issue with an email address that contains a dash.
I'm not 100% sure but it looks like the cause is the display: inline-block
you introduced with "Use bidi-overide > isolate-overide for browser compatibility" (8e75c4a). If I remove that, the email address looks fine again.
Describe the bug
I'm using this package with GatsbyJS, it works fine in the local build or develop, however on deploying to Netlify I get the following error:
Can't resolve 'react' in '/opt/build/repo/node_modules/react-obfuscate/dist'
6:43:45 PM: File: ../node_modules/react-obfuscate/dist/obfuscate.js
Additional context
I'm getting the following as advice from VSCode:
module "..../node_modules/react-obfuscate/dist/obfuscate"
Could not find a declaration file for module 'react-obfuscate'. '..../node_modules/react-obfuscate/dist/obfuscate.js' implicitly has an 'any' type.
Try npm install @types/react-obfuscate
if it exists or add a new declaration (.d.ts) file containing declare module 'react-obfuscate';
ts(7016)
On initial install into a simple project, I receive a full-page critical error within this package. This should be a simple fix of removing this package's dependency on prop-types
.
./~/react-obfuscate/dist/obfuscate.js
Module not found: Error: Cannot resolve module 'prop-types' in /Users/Dawson/code/personal/www/node_modules/react-obfuscate/dist
resolve module prop-types in /Users/Dawson/code/personal/www/node_modules/react-obfuscate/dist
looking for modules in /Users/Dawson/code/personal/www/node_modules/next/node_modules
/Users/Dawson/code/personal/www/node_modules/next/node_modules/prop-types doesn't exist (module as directory)
resolve 'file' prop-types in /Users/Dawson/code/personal/www/node_modules/next/node_modules
resolve file
/Users/Dawson/code/personal/www/node_modules/next/node_modules/prop-types doesn't exist
/Users/Dawson/code/personal/www/node_modules/next/node_modules/prop-types.webpack.js doesn't exist
/Users/Dawson/code/personal/www/node_modules/next/node_modules/prop-types.web.js doesn't exist
/Users/Dawson/code/personal/www/node_modules/next/node_modules/prop-types.js doesn't exist
/Users/Dawson/code/personal/www/node_modules/next/node_modules/prop-types.json doesn't exist
looking for modules in /Users/Dawson/code/personal/www/node_modules
/Users/Dawson/code/personal/www/node_modules/prop-types doesn't exist (module as directory)
resolve 'file' prop-types in /Users/Dawson/code/personal/www/node_modules
resolve file
/Users/Dawson/code/personal/www/node_modules/prop-types doesn't exist
/Users/Dawson/code/personal/www/node_modules/prop-types.webpack.js doesn't exist
/Users/Dawson/code/personal/www/node_modules/prop-types.web.js doesn't exist
/Users/Dawson/code/personal/www/node_modules/prop-types.js doesn't exist
/Users/Dawson/code/personal/www/node_modules/prop-types.json doesn't exist
looking for modules in /Users/Dawson/code/personal/www/node_modules
/Users/Dawson/code/personal/www/node_modules/prop-types doesn't exist (module as directory)
resolve 'file' prop-types in /Users/Dawson/code/personal/www/node_modules
resolve file
/Users/Dawson/code/personal/www/node_modules/prop-types doesn't exist
/Users/Dawson/code/personal/www/node_modules/prop-types.webpack.js doesn't exist
/Users/Dawson/code/personal/www/node_modules/prop-types.web.js doesn't exist
/Users/Dawson/code/personal/www/node_modules/prop-types.js doesn't exist
/Users/Dawson/code/personal/www/node_modules/prop-types.json doesn't exist
[/Users/Dawson/code/personal/www/node_modules/next/node_modules/prop-types]
[/Users/Dawson/code/personal/www/node_modules/next/node_modules/prop-types]
[/Users/Dawson/code/personal/www/node_modules/next/node_modules/prop-types.webpack.js]
[/Users/Dawson/code/personal/www/node_modules/next/node_modules/prop-types.web.js]
[/Users/Dawson/code/personal/www/node_modules/next/node_modules/prop-types.js]
[/Users/Dawson/code/personal/www/node_modules/next/node_modules/prop-types.json]
[/Users/Dawson/code/personal/www/node_modules/prop-types]
[/Users/Dawson/code/personal/www/node_modules/prop-types]
[/Users/Dawson/code/personal/www/node_modules/prop-types]
[/Users/Dawson/code/personal/www/node_modules/prop-types]
[/Users/Dawson/code/personal/www/node_modules/prop-types.webpack.js]
[/Users/Dawson/code/personal/www/node_modules/prop-types.webpack.js]
[/Users/Dawson/code/personal/www/node_modules/prop-types.web.js]
[/Users/Dawson/code/personal/www/node_modules/prop-types.web.js]
[/Users/Dawson/code/personal/www/node_modules/prop-types.js]
[/Users/Dawson/code/personal/www/node_modules/prop-types.js]
[/Users/Dawson/code/personal/www/node_modules/prop-types.json]
[/Users/Dawson/code/personal/www/node_modules/prop-types.json]
@ ./~/react-obfuscate/dist/obfuscate.js 15:17-38
Describe the bug
Que using react-obfuscate on a Next.js repository, Google complains of non existing links caused by the library. All these links have the /obfuscate in the URL.
To Reproduce
Expected behavior
I expect that the website either doesn't have that link or doesn't render the component at all on SSR. Also, consider CSR because it might happen the same.
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates are awaiting their schedule. Click on a checkbox to get an update now.
@commitlint/cli
, @commitlint/config-conventional
, eslint-plugin-react-hooks
)react
, react-dom
)These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
.github/workflows/nodejs-ci.yml
actions/checkout v3
actions/setup-node v3
.github/workflows/release.yml
actions/checkout v3
actions/setup-node v3
package.json
@babel/cli 7.24.1
@babel/core 7.24.4
@babel/eslint-parser 7.24.1
@babel/plugin-transform-runtime 7.24.3
@babel/plugin-transform-spread 7.24.1
@babel/preset-env 7.24.4
@babel/preset-react 7.24.1
@commitlint/cli 19.2.1
@commitlint/config-conventional 19.1.0
@testing-library/jest-dom ^6.4.2
@testing-library/react ^15.0.2
babel-jest 29.7.0
coveralls 3.1.1
eslint ^8
eslint-config-airbnb 19.0.4
eslint-config-prettier 9.1.0
eslint-plugin-import 2.29.1
eslint-plugin-jsx-a11y 6.8.0
eslint-plugin-prettier 5.1.3
eslint-plugin-react 7.34.1
eslint-plugin-react-hooks 4.6.0
husky 9.0.11
jest ^29.7.0
jest-environment-jsdom ^29.7.0
lint-staged 15.2.2
next 13.4.7
prettier 3.2.5
prop-types 15.8.1
react 18.2.0
react-dom 18.2.0
react-live 4.1.6
react-window-ui 2.2.0
prop-types >= 15
react >= 16.8
react-dom >= 16.8
node >= 0.10.0
.nvmrc
node 20
.travis.yml
Hi guys. Very helpful component; thanks to everyone who contributed!
Project I'm working on has strict types and I've defined basic type declarations for the Obfuscate
component.
Are you willing to bundle complete types with the NPM package if I create a pull request containing them?
I have an address
block like this:
<address>
<Obfuscate email="[email protected]" />
<br />
<Obfuscate tel="+420 111 222 333" />
</address>
The second link always turns and stays backwards when I mouse over it.
I started just randomly messing with the tags and characters around Obfuscate
to see what would happen and managed to work around the problem by doing this:
<address>
<span>
{' '}
<Obfuscate email="[email protected]" />
</span>
<br />
<span>
{' '}
<Obfuscate tel="+420 111 222 333" />
</span>
</address>
There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.
Error type: Cannot find preset's package (github>whitesource/merge-confidence:beta)
It would be nice if link text was obscured, even if it may not need to be. Below I have an example of a human formatted phone number as the link text. It doesn't get obscured, which kind of defeats the purpose of using Obfuscate
. I could "work around" this by simply omitting the children
prop, but then the nicely formatted number would not be displayed.
const telephone = '+15553219876';
const formatted = '+1 555 321.9876';
<Obfuscate tel={telephone}>{formatted}</Obfuscate>
Before interaction:
<a href="obfuscated" style="unicode-bidi: isolate-override; direction: ltr;">+1 919 321.9876</a>
After interaction:
<a href="obfuscated" style="unicode-bidi: isolate-override; direction: ltr;">+1 919 321.9876</a>
I want to use an inline SVG letter icon as child inside <Obfuscate>
, but this unfortunately does not work.
<Obfuscate email={'user@localhost'}>
<svg viewBox="0 0 24 24">
<!-- ... -->
</svg>
</Obfuscate>
It fails when calling this.reverse(propsList)
here https://github.com/coston/react-obfuscate/blob/master/src/obfuscate.js#L99.
Are there plans to support this?
Is your feature request related to a problem? Please describe.
Assuming a normal build process and the example usage described in README.md
, the example input produces an output that specifies the email in plaintext in the .js
that is served. In this case, usage of react-obfuscate provides no protection, because certainly a malicious web-crawler which goes to the greater difficulty of rendering the DOM to harvest emails will also scan the .js
for emails.
Describe the solution you'd like
I suggest that README.md
should not claim that the <Obfuscate>
component makes the email or link given in the example useless for spammers, and should detail the additional steps required to protect emails and links from spammers.
Given that there are 12,000 downloads per month for this package, improving it to obfuscate the children and props of the <Obfuscate>
tag in the compiled source might be worth doing.
Describe alternatives you've considered
javascript-obfuscator can be used mangle string literals in source code appropriately, or they might be scrambled by hand and recovered with vanilla JavaScript.
When using multiple obfuscations and using css columns, the first obfuscation doesn't display properly, but fixes itself after hover, the code I am using:
<div with class columns>
...
<p className="staff serif">
<em>Staff</em>
<br />
{site.member.map((member, i) => (
<React.Fragment key={i}>
<Obfuscate
style={{ display: "inline-block" }}
email={member.email}
>{`${member.name}, ${member.role}`}</Obfuscate>
{site.member[i + 1] && <br />}
</React.Fragment>
))}
</p>
...
</div with class columns>
In the above code, the first member appears text-aligned right, with the words in reverse order, until I hover on them and they then appear properly.
When I remove the css columns property from the div, this fixes the issue.
1.18.2
to 1.19.0
.This version is covered by your current version range and after updating it in your project the build failed.
prettier is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
9.1.1
to 9.1.2
.This version is covered by your current version range and after updating it in your project the build failed.
next is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
@zeit/fetch
example: #9074react(-dom)@canary
Every 12 Hours: #9151next
dist-tag: #9165react-ssr-prepass
from Next Deps: #9224Huge thanks to @tusbar, @karlhorky, @sebastianbenz, @ykzts, @manfwh, @ijjk, @ismamz, @sandrinodimattia, @armspkt, @timneutkens, @lfades, @rafaelalmeidatk, @SZharkov, @Baukaalm, @iNishant, @devknoll, @atcastle, @guswnsxodlf, @s-h-a-d-o-w, @HaNdTriX, @resir014, @firstziiz, @melanieseltzer, @iliran11, @Timer, @masives, @none23, @acdlite, @taylorbryant, @zackkrida, @htbvo, @midudev, @bitjson, @ctavan, @YUFENGWANG, @Janpot, @flybayer, @meuwka, @kachkaev, and @juanmiguelbesada for helping!
The new version differs by 102 commits.
acf7d0a
v9.1.2
07b46d7
Update examples: static export using dynamic routes instead exp… (#9237)
cb7a184
v9.1.2-canary.10
d40f010
Delete _document.js (#9236)
4dbd267
Split TypeScript Flag Docs (#9231)
f5969d2
Restore package.json and yarn.lock to allow deploy (#9230)
14ed867
Disable worker_threads by default for firebase compatibility (#9199)
ad2a3d6
Add configuration flags to disable integrated type checker (#9138)
2d9f199
Add warning for getStaticParams without getStaticProps (#9226)
34e0ce6
Remove react-ssr-prepass
from Next Deps (#9224)
4584ea4
Fix examples #9064: bumps next-redux-wrapper package version that contains babel runtime fix (#9214)
1c11ffd
Fix react-native-web example by adding babel plugin (#9078)
ab0a864
API: Take multiple values into account for the query (#9196)
20978af
v9.1.2-canary.9
211c84e
allow NextScript to optionally defer javascript (#8980)
There are 102 commits in total.
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
It would be great if this package didn't rely on Prop-Types.
I know it's basically a core of the obfuscation of the package, but it has one really big downside - many people don't click on a link but copy it and then paste it to their email app. And with this package, the pasted email is backwards. Would it be possible to solve this somehow?
Just wanted to say thank you for the snippet here: https://react-obfuscate.coston.io/ where you have Child Elements
Maybe you could put that example on the primary package Readme.md? That would help others in future.
Thank you,
To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:
.travis.yml
package.json
files, so that was left aloneIf you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.
Greenkeeper has checked the engines
key in any package.json
file, the .nvmrc
file, and the .travis.yml
file, if present.
engines
was only updated if it defined a single version, not a range..nvmrc
was updated to Node.js 10.travis.yml
was only changed if there was a root-level node_js
that didn’t already include Node.js 10, such as node
or lts/*
. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.For many simpler .travis.yml
configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
Is your feature request related to a problem? Please describe.
I'm using Obfuscate
with Chakra UI, a component library for React, that provides a Link component that is already on-brand and with useful utilities. Obfuscate
works fine passing a React element type in the element
prop, but the prop types validation expects only a string, not a React element type.
Example usage:
import { Link } from '@chakra-ui/react';
import Obfuscate from 'react-obfuscate';
function MyComponent() {
return (
<Obfuscate email="[email protected]" element={Link} />
);
}
This works, but it produces the following console error log:
Warning: Failed prop type: Invalid prop `element` of type `object` supplied to `Obfuscate`, expected `string`.
Describe the solution you'd like
Probably just update the following line:
// obfuscate.js line 129
- element: T.string,
- element: T. oneOfType([T.string, T.elementType]),
Line: https://github.com/coston/react-obfuscate/blob/master/src/obfuscate.js#L129
and add a unit test for this scenario.
Describe alternatives you've considered
No alternatives considered yet!
--
I'd be happy to make this contribution, just want to open the issue first in case the element
prop only accepts strings by design.
Thanks
--
EDIT: I realized later that there's a problem with the output, and the resulting a
tag when setting element={Link}
doesn't have an href
😅. That is because of the check here that is specifically doing Component === 'a'
. Is there a reason for that, or could it be removed to pass those props in all cases?
Refactor tests to use Jest + React Testing Library for better maintainability. This may also help with #280.
Is your feature request related to a problem? Please describe.
N/A
Describe the solution you'd like
I would like to have a className
prop instead of wrapping component in a div
/p
Describe alternatives you've considered
Wrapping the component in an HTML element like p
Additional context
N/A
Thank you!
<Obfuscate
element="a"
href="https://www.google.com"
target="_blank"
style={{
textAlign: "left",
}}
>
Click Here
</Obfuscate>
Having target="_blank"
does not open a new tab, but instead directs current window to the href
.
Describe the bug
When hovering over an obfuscated link the the text moves to the left around 2px.
To Reproduce
Steps to reproduce the behavior:
I was trying to add a "click to whatsapp chat" on my page which is a regular href link with the user's phone number.
https://wa.me/phonenumber
https://faq.whatsapp.com/en/android/26000030/
Some other apps, such as skype use href="skype:.."
. Would it be possible for the user to specify a custom url and protocol so react-obfuscate
could virtually support any url?
devDependency
@babel/cli was updated from 7.6.4
to 7.7.0
.devDependency
@babel/core was updated from 7.6.4
to 7.7.0
.devDependency
@babel/preset-env was updated from 7.6.3
to 7.7.0
.devDependency
@babel/preset-react was updated from 7.6.3
to 7.7.0
.This version is covered by your current version range and after updating it in your project the build failed.
This monorepo update includes releases of one or more dependencies which all belong to the babel7 group definition.
babel7 is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
I tried using the linkText property but it didn't work. For example:
<Obfuscate tel="1-800-222-333" linkText="800.222.333" />
However, the following works fine. I wonder if the readme.md
needs to be updated.
<Obfuscate tel="1-800-222-333">800.222.333</Obfuscate>
There are no type-definitions for this package here or on DefinitelyTyped.
This way it can not be properly used in Typescript projects.
Please add these if possible. Would be much appreciated. 🙏
Currently when used with my SSR node app on internet explorer 11 and Edge the phone number is reversed when its displayed until I mouse over the number where it will fix the rendering of it, and show the phone number correctly.
🚨 You need to enable Continuous Integration on all branches of this repository. 🚨
To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.
Since we didn’t receive a CI status on the greenkeeper/initial
branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.
If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/
.
Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial
branch in this repository, and then remove and re-add this repository to the Greenkeeper integration’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.