From 5d88c5803c20b96515624e129cc3fc864f2a9f11 Mon Sep 17 00:00:00 2001 From: Mohamed Rejeb <41842296+MohamedRejeb@users.noreply.github.com> Date: Fri, 1 Sep 2023 18:08:44 +0100 Subject: [PATCH] Fix IndexOutOfBounds when parsing a wrong Html (#22) * Fix issue with encoding some html entities * Fix issues with decoding emoji * Fix IndexOutOfBounds when parsing a wrong Html --- .../ksoup/html/parser/KsoupHtmlParser.kt | 2 +- .../ksoup/html/KsoupHtmlParserTest.kt | 13 + .../com/mohamedrejeb/ksoup/html/TestData.kt | 749 ++++++++++++++++++ 3 files changed, 763 insertions(+), 1 deletion(-) create mode 100644 ksoup-html/src/commonTest/kotlin/com/mohamedrejeb/ksoup/html/TestData.kt diff --git a/ksoup-html/src/commonMain/kotlin/com/mohamedrejeb/ksoup/html/parser/KsoupHtmlParser.kt b/ksoup-html/src/commonMain/kotlin/com/mohamedrejeb/ksoup/html/parser/KsoupHtmlParser.kt index cb838a1..a80ab35 100644 --- a/ksoup-html/src/commonMain/kotlin/com/mohamedrejeb/ksoup/html/parser/KsoupHtmlParser.kt +++ b/ksoup-html/src/commonMain/kotlin/com/mohamedrejeb/ksoup/html/parser/KsoupHtmlParser.kt @@ -184,7 +184,7 @@ public class KsoupHtmlParser( this.endOpenTag(isOpenImplied) // Self-closing tags will be on the top of the stack - if (this.stack[this.stack.size - 1] == name) { + if (this.stack.getOrNull(this.stack.size - 1) == name) { // If the opening tag isn't implied, the closing tag has to be implied. this.handler.onCloseTag(name, !isOpenImplied) this.stack.removeLast() diff --git a/ksoup-html/src/commonTest/kotlin/com/mohamedrejeb/ksoup/html/KsoupHtmlParserTest.kt b/ksoup-html/src/commonTest/kotlin/com/mohamedrejeb/ksoup/html/KsoupHtmlParserTest.kt index bdc4d08..ed5c345 100644 --- a/ksoup-html/src/commonTest/kotlin/com/mohamedrejeb/ksoup/html/KsoupHtmlParserTest.kt +++ b/ksoup-html/src/commonTest/kotlin/com/mohamedrejeb/ksoup/html/KsoupHtmlParserTest.kt @@ -270,4 +270,17 @@ class KsoupHtmlParserTest { expectedString = "First lineSecond line", ) } + + @Test + fun testBigHtml() { + val handler = KsoupHtmlHandler + .Builder() + .build() + + val ksoupHtmlParser = KsoupHtmlParser( + handler = handler, + ) + ksoupHtmlParser.write(TestData.htmlString) + ksoupHtmlParser.end() + } } \ No newline at end of file diff --git a/ksoup-html/src/commonTest/kotlin/com/mohamedrejeb/ksoup/html/TestData.kt b/ksoup-html/src/commonTest/kotlin/com/mohamedrejeb/ksoup/html/TestData.kt new file mode 100644 index 0000000..c2e2ab9 --- /dev/null +++ b/ksoup-html/src/commonTest/kotlin/com/mohamedrejeb/ksoup/html/TestData.kt @@ -0,0 +1,749 @@ +package com.mohamedrejeb.ksoup.html + +object TestData { + val htmlString = """ +

For people who want to see the world without f***ing up their mental, physical & financial health

+ + + +

Table Of Contents

+ + + + + + + +
+ + + +

Getting Lost In A City – A Parisian Anecdote

+ + + +

I’m writing this from a cafe here in Paris, a proper Parisian cafe with the colored chairs sitting two by each other behind small round tables. In front of me the city is buzzing, There’s a swarm of cars, motorcycles, bikes, mentally ill people yelling.

+ + + +

It’s a controlled anarchy that I love. The reason I love cities. Then add to this the architecture, culture, cuisine and language of France and you have Paris. Which is without a doubt one of my favorite cities in the world. See my complete digital nomad guide for Paris here.

+ + + +
+ +
A shot from one of my favorite cafe’s to work from in Paris.
+ + + +

I’ve been taking intensive French classes, which has me at a school for 5 hours a day speaking nothing but French and learning about pronunciation, vocabulary, and grammar (the latter is a bit of a nightmare).

+ + + +

I got to Paris nearly a week ago and I’ve been wrapped up in it all. Wrapped up in the energy of the city, the buzz, the eagerness to get my French back to where it was before, and even better.

+ + + +

The energy of this city is palpable to me, and I feel alive. I feel alive the same way I did hiking through the German & Austrian Alps (see my Austrian digital nomad guide here) or spending time with women I’ve been in love with (see my travel love stories here). Food tastes better. The buildings and people I’d normally let fall into the background unnoticed, I’m appreciating. I feel alive.

+ + + +

It’s easy to get caught up in this high, to lose sight of my emotional, physical & financial well-being and get wrapped up in the sights, sounds and people around me.

+ + + +

I’ve done this a million times. As someone without any strong ties to any one place I can live my entire life chasing novelty.

+ + + +

If I get tired of a woman I’m dating, just find a new one. If I get tired of a place I’m at just move to a new spot. If I get tired of the friends I’m around, get new ones.

+ + + +

I’ve gone through dozens of cities, friends and women only to realize that if I can’t find stability and peace in my travels then I’ll remain unsatisfied and alone.

+ + +
+
Dating While Traveling - Thailand
+ + +

A photo from Thailand with my then girlfriend, click here to read my dating and traveling stories

+ + + +

Instead of looking inward at my responsibility for the lack of joy, fulfillment, connection I’ll project the issue externally.

+ + + +

It’s X’s fault that I’m not feeling fulfilled from this relationship. It’s the shitty weather here that’s making me depressed. It’s because of my emotionally distant friends that I’m not feeling connected.

+ + + +

You can always find an external thing to blame your dissatisfaction on, and if you’re like me then you can keep changing those external things, until you’re exhausted and nowhere left to look but inside.

+ + + +
+ +
A video I shot up in Franschhoek, South Africa. A country I love but where I was guilty of losing sight of balancing my mental / spiritual health. Check out my digital nomad guide to Cape Town here.
+ + + +
+ + + +

So Why Do I Journal?

+ + + +

I journal for a multitude of reasons, but the biggest reason is to (try to) stay calm and centered regardless of what’s going on around me.

+ + + +

Journalling gives me more insight into how I’m feeling, what I’m dissatisfied with and how to improve my mood for the day.

+ + + +

That keeps me from blaming my dissatisfaction on the world around me, it gives me the power to control my emotions.

+ + + +

In addition to this, there are some other benefits I get from journalling

+ + + +
+ +
+ + + +

A video from my last trip to Costa Rica. Where I started getting more serious about my journalling

+ + + +
+
View this post on Instagram

A post shared by Digital Nomad Lifestyle (@officialdigitalnomadlifestyle)

+
+ + + +
+ + + +

Important Notes, Tips & Explanations About Journalling

+ + + +
    +
  1. I do not journal daily, or complete all of this tasks as much as I’d like. + +
  2. + + + +
  3. The goal of journaling isn’t to fill everything out 100% and fully optimize my morning process, etc. the goal is to better understand myself, what gives me energy, what takes energy away and reminding myself about what I truly care about. + +
  4. + + + +
  5. This template isn’t set in stone + +
  6. + + + +
  7. But journalling in the morning takes up a lot of time, I got things to do! + +
  8. +
+ + + +

A video of me writing in my journal in a beautiful cabin in Santa Helena, Colombia

+ + + +
+ +
+ + + +
+ + + +

My Daily Journal Template

+ + + +
    +
  1. What Am I Happy About From Yesterday?
  2. + + + +
  3. What Did I Do Yesterday That I’d Like To Improve On Today?
  4. + + + +
  5. Gratitude – 5 Things I’m Grateful For Right Now
  6. + + + +
  7. 3 Main Foci + +
  8. + + + +
  9. My Notes Section
  10. +
+ + +
+
Example Daily Journal Template
+ + +

A snapshot of a couple days in my journal

+ + + +
+ + + +

Breakdown of The Sections Of My Daily Journaling

+ + + +

What Am I Happy About From Yesterday?

+ + + +

Admittedly, I’m not great at always doing this part and the next. But this can be a great way to kickstart my gratitude for the day, and also build some positive momentum going into the day.

+ + + +

What Did I Do Yesterday That I’d Like To Improve On Today?

+ + + +

I always tell my employees that making the same mistakes over and over again are how businesses fail. It’s not too different for people either, making the same mistakes over and over again is a recipe for disaster.

+ + + +

This process can really expedite identifying recurring issues and shortening their lifetime.

+ + + +

Gratitude – 5 Things I’m Grateful For Right Now

+ + +
+
Cycling Through Greece - Katerini
+ + +

A shot from my bike ride through Greece & Turkey, gratitude is a necessity for these rides

+ + + +

A couple tips to gratitude

+ + + +
    +
  1. Try not to repeat the same things every morning – this is easy to do, and can keep you from fully experiencing the practice.
  2. + + + +
  3. Try to list out the details of what you’re grateful for, as well as why you’re grateful for it. + +
  4. + + + +
  5. Notice your emotions, gratitude is an emotion if you’re not feeling any changes to your emotions you may need to switch things up.
  6. + + + +
  7. You can also use gratitude as an affirmation of things to come. I’m grateful that (X) injury will be fixed, I’m grateful that I’ll get that raise by the end of the month, etc.
  8. + + + +
  9. One thing I started doing on my longer bike rides when I was having a hard time switching over into gratitude was what I call gratitude bombs. + +
  10. +
+ + + +

3 Main Foci

+ + + +

A lot of journal prompts will have you outline your 1 – 5 goals for the day, I really liked this idea and I transformed it a bit.

+ + + +

Everyday I journal I want to outline what I’m going to do today for my mental / spiritual health, my physical health and finally my financial / career health.

+ + + +

This order is very important to me.

+ + + +

My Mental health is #1, my physical health comes second, and then my career and financial health. I don’t always get this order right, but it’s a big intention of mine.

+ + + +

I don’t care how much money I make, if I’m not in the physical shape I want to be in, I’m not going to be fulfilled.
I can also make a bunch of money and be in great shape, but if I’m not taking care of my mental health and I’m feeling miserable that’s not the life I want to live either.

+ + +
+
ripped dude on a beach
+ + +

A shot of me when I was in Vietnam. In great shape, but largely ignoring my mental health. Learn more about my journey to being a digital nomad here.

+ + + +

So I start my mornings reinforcing what’s most important to me.

+ + + + + + + +
+

Looking back now, could I have achieved the financial / career success I have now if I had been more focused on my mental health while I was climbing the career ladder?

+ + + +

I don’t know… so maybe my lack of introspection served me for building a career, but at this point I’m not interested in regularly trading happiness today for money tomorrow.

+
+ + + +

My Mental / Spiritual Health

+ + + +

Here’s a breakdown of what I try to do everyday

+ + + + + + + + + + + +

A shot of me journalling in Cancun, Mexico. Where I started getting more in touch with my emotions. Interested in digital nomadding in Mexico, check out my guide for Mexico City or Playa Del Carmen.

+ + + +
+ +
+ + + +

I would recommend everyone who regularly engages in behaviors they want to change to take some time to look through this list of human needs and figure out which needs they’re getting met through those behaviors and how they can find healthier ways to get those needs met.

+ + + +

After struggling with overeating, drinking to feel better and relying on sex and women to feel good I’ve started outlining daily how I can get my most important needs met and it helps keep the urges (more) under control.

+ + + +

Do I still slip up? Absolutely, but outlining healthier ways to get these needs met daily has really helped me in mitigating the occurrences and duration of my slip-ups.

+ + + +

So everyday I try to outline 1 – 3 healthier ways I can get these 4 needs met.

+ + + +

My Physical Goals For The Day

+ + + +

A shot of me in Portugal, not nearly as lean as my photo from Vietnam above, but not bad for someone who’s on the move. Check out my digital nomad guide for Lisbon here.

+ + +
+
Nova Praia, Lisbon Portugal
+ + +

This is a huge one, especially for people who travel and want to stay fit. Having a clear plan for my diet and exercise at the beginning of each day is absolutely essential for staying fit wherever I’m at.

+ + + +

For me this generally breaksdown into a couple of things

+ + + +
    +
  1. My diet – what I’m going to eat that day
  2. + + + +
  3. Stretching, band work – work to keep my body loose and mitigate injuries (or worsening existing injuries)
  4. + + + +
  5. Exercise – what exercise I’m going to do that day
  6. +
+ + + +

Career / Financial Work

+ + + +

A shot of me in Rio De Janeiro, back when I was working office jobs, and far more focused on my career & financial health, over my physical / mental health.

+ + +
+
Rio De Jainero Be
+ + +

For this section, ideally I want to find the 1 – 2 things I can do for my businesses that are going to have the biggest impact on my long-term business health. Here’s a podcast about figuring out your ${'$'}10, ${'$'}100 & ${'$'}1,000 tasks (I’m actually working through this week) to determine what those big tasks are.

+ + + +

The goal is to constantly be evaluating what I’m doing throughout the day for work. Is this something that’s in my zone of Genius ( and worth ${'$'}1,000 an hour)?

+ + + +

If not, then I need to build out a process, and train someone else to do it. If it’s not important enough to train someone else to do it, then I need to really re-consider whether I should be doing it at all.

+ + + +

The vision board I created when I started my digital marketing business. I used to look at that photo of the labtop and the mountains in the background on a weekly basis dreaming about where I am today. I’m incredibly lucky, and I know that journalling has helped me immensely in getting here.

+ + +
+
vision board example for men
+ + +

My Notes Section

+ + + +

This is where I put my notes in for the day, what am I thinking about? What would I like to get off my chest? Etc.

+ + + +

I know people who will set a timer for 10 – 15 minutes to ensure that they get some free form writing out, I don’t do that but do think it’s a good idea for sure.

+ + + +

My Quarterly Journalling Practices

+ + + +

So every 3 months I swap out my journal for a new one. I do this for a couple of reasons.

+ + + +
    +
  1. This allows me to review my intentions, goals, visions for the future
  2. + + + +
  3. I also use these journals as time capsules of the things I did. Where I can look back later on and remember where I was at in that quarter, what I was doing, etc.
  4. +
+ + + +
+ +
Showing how I use my journals as time capsules of my trips
+ + + +

Here’s the list of my quarterly journalling practices

+ + + +
    +
  1. Listing out healthier ways I can get my main needs met + +
  2. + + + +
  3. My IntentionsHow do I want to live my daily life + + + + + + + +
  4. +
+ + + +
+ + + +

A Couple Articles About Goal Setting

Goal Setting & How Goals Change

+ + + +

Why I Don’t Focus On Goal Setting Anymore

+ + + +
+ + + +
    +
  1. My Bucket List – List of things I want to do before my 40th Birthday. + +
  2. + + + +
  3. Where Do I Want To Be At 40? Listing out how I want my life to look like at 40, broken down into 4 categories + +
  4. +
+ + + +
+ + + +

🙋‍♀️ Want to stay up to date on my journey?

+ + + +

Or – Looking For Regular Digital Nomad Content & Inspiration? 🙋‍♀️

+ + + +

Follow Me On Instagram – @officialdigitalnomadlifestyle

+

The post Daily Journalling, Goal & Intention Setting appeared first on Digital Nomad Lifestyle.

+""" +} \ No newline at end of file