Skip to content

Update examples to not combine density and width#12

Merged
sindresorhus merged 2 commits intosindresorhus:mainfrom
nfriedly:patch-1
May 6, 2021
Merged

Update examples to not combine density and width#12
sindresorhus merged 2 commits intosindresorhus:mainfrom
nfriedly:patch-1

Conversation

@nfriedly
Copy link
Contributor

@nfriedly nfriedly commented May 5, 2021

Hey, thanks for making this library!

PR #6 updated the codebase to not allow density and width to be combined when parsing. (Although, amusingly, it does still allow it when stringifying - kind of the opposite of the robustness principle.)

This updates the readme to match so that the examples are correct and parse-able.

On a related note, would you be interested in another PR to make stringifying more strict? Also, what about a not-strict mode that does it's best and doesn't throw errors? (It would be handy for my use-case. For the moment I'm just wrapping this in a try/catch and using the original value if it throws.)

Hey, thanks for making this library!

sindresorhus#6 updated the codebase to not allow density and width when parsing. (Although, amusingly, it does still allow it when stringifying - kind of the opposite of the robustness principle.)

This updates the readme to match so that the examples are correct and parse-able.

On a related note, would you be interested in another PR to make stringifying more strict? Also, what about a not-strict mode that does it's best and doesn't throw errors? (It would be handy for my use-case. For the moment I'm just wrapping this in a try/catch and using the original value if it throws.)
@sindresorhus
Copy link
Owner

On a related note, would you be interested in another PR to make stringifying more strict?

Sure

Also, what about a not-strict mode that does it's best and doesn't throw errors? (It would be handy for my use-case. For the moment I'm just wrapping this in a try/catch and using the original value if it throws.)

What's the use-case?

@sindresorhus sindresorhus merged commit e3f8b25 into sindresorhus:main May 6, 2021
@nfriedly
Copy link
Contributor Author

nfriedly commented May 6, 2021

What's the use-case?

I made a web proxy so that if you're on a filtered internet connection, you can give the proxy a url and it will go fetch the contents and rewrite all of the links and images and whatnot to go through the proxy. It mostly gets used by kids in school, but I have seen some more "legitimate" use - e.g. people Turkey or Iran bypassing their government's filters, or people who were traveling and needed to get around GeoIP restrictions.

It previously used regex's to rewrite everything, but I've been rebuilding it to use a proper html parser, and I grabbed this library to parse srcsets and rewrite the urls. But I don't really care if the attribute is valid or not, that's the responsibility of the original website, not my proxy. So I'd prefer a "loose" mode that just did it's best and never threw any errors.

This is what I have right now:

https://github.com/nfriedly/node-unblocker/blob/06cc2100c301a95a8599c9211c23ebbaeb8d7f56/lib/rewrite-html.js#L47-L58

@sindresorhus
Copy link
Owner

PR welcome for a loose mode.

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

Successfully merging this pull request may close these issues.

2 participants