fix: make comment vote parsing more robust
This commit is contained in:
@@ -140,6 +140,46 @@ class ApiTest {
|
||||
assertThat(postDetails.comments.single().score).isEqualTo(1)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `comments use upvoter title when the visible score is omitted`() {
|
||||
val parser = LobstersParserServiceImpl()
|
||||
|
||||
val postDetails =
|
||||
parser.parsePostDetails(
|
||||
"""
|
||||
<ol class="stories">
|
||||
<li class="story" data-shortid="story1">
|
||||
<span class="link h-cite"><a href="/s/story1/test">Test story</a></span>
|
||||
<div class="byline">
|
||||
<a class="u-author" href="/~/submitter">submitter</a>
|
||||
<time data-at-unix="1710000000"></time>
|
||||
</div>
|
||||
</li>
|
||||
</ol>
|
||||
<ol class="comments">
|
||||
<li class="comments_subtree">
|
||||
<div class="comment" data-shortid="abc123">
|
||||
<div class="voters">
|
||||
<label for="comment_folder_abc123" class="comment_folder"></label>
|
||||
<a class="upvoter" title="12" href="/login"></a>
|
||||
</div>
|
||||
<div class="details">
|
||||
<div class="byline">
|
||||
<a href="/~/author">author</a>
|
||||
<a href="/c/abc123"><time data-at-unix="1710000000"></time></a>
|
||||
</div>
|
||||
<div class="comment_text"><p>Hello</p></div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ol>
|
||||
"""
|
||||
.trimIndent()
|
||||
)
|
||||
|
||||
assertThat(postDetails.comments.single().score).isEqualTo(12)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `edited comments expose a single timestamp and edited state`() = runTest {
|
||||
val postDetails = api.getPostDetails("tdfoqh")
|
||||
|
||||
+59
-59
@@ -24,16 +24,16 @@
|
||||
<link href="https://lobste.rs/s/tdfoqh/ranking_comments_by_sum_replies_scores" rev="canonical" rel="self alternate shorter shorturl shortlink">
|
||||
<title>Ranking comments by sum of replies' scores | Lobsters</title>
|
||||
|
||||
<link rel="stylesheet" href="/assets/application-8d029e37.css">
|
||||
<link rel="stylesheet" href="/assets/application-d417b8b4.css">
|
||||
<link rel="stylesheet" href="/assets/system-system-fd030c9d.css">
|
||||
<link rel="stylesheet" href="/assets/tom-select-00e8031d.css" data-turbo-track="reload">
|
||||
<link rel="stylesheet" href="/assets/TomSelect_remove_button-4d5c34b9.css" data-turbo-track="reload">
|
||||
|
||||
|
||||
<meta name="csrf-param" content="authenticity_token">
|
||||
<meta name="csrf-token" content="4i6TIGJDGnIZG7YaRMHPyYYg-LoCzf2nZznREoRDfQv26Eln3eTfll3z-c6sypfCq2kn5OtRI3_cD3ZCNQOe4Q">
|
||||
<meta name="csrf-token" content="x21lNnPzmG8xQppD1ULd26ofux_9rIbRINBAnkeKXk41Y0_S_aEHvYVgGU3yku7qxVwIpN5vOxWJoX07PHF4JA">
|
||||
<meta name="robots" content="noai, noimageai">
|
||||
<script type="speculationrules" nonce="0Tcy0yahOOA5lchr3moUHw==">
|
||||
<script type="speculationrules" nonce="KRObbTozM4i2tL2NUL7DWQ==">
|
||||
{
|
||||
"prefetch": [
|
||||
{
|
||||
@@ -46,9 +46,9 @@
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body data-username='' data-now-unix='1780070763'>
|
||||
<body data-username='' data-now-unix='1783665557'>
|
||||
<header id="nav">
|
||||
<a id="logo" style="background-color: #6e0000;" href="/" title="Lobsters (Current traffic: 17%)"></a>
|
||||
<a id="logo" style="background-color: #5b0000;" href="/" title="Lobsters (Current traffic: 6%)"></a>
|
||||
|
||||
|
||||
<div class="navholder">
|
||||
@@ -99,13 +99,13 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
* the first reply has 12 points,
|
||||
* and, in total, 18 points have been accumulated by all the r..." href="/s/tdfoqh/ranking_comments_by_sum_replies_scores">☶</a>
|
||||
|
||||
<span class="tags">
|
||||
<a class="tag tag_meta" title="Lobsters-related bikeshedding - report bugs at https://github.com/lobsters/lobsters" href="/t/meta">meta</a>
|
||||
</span>
|
||||
<ul class="tags" aria-label="Tags">
|
||||
<li><a aria-label="Tag meta" class="tag tag_meta" title="Lobsters-related bikeshedding - report bugs at https://github.com/lobsters/lobsters" href="/t/meta">meta</a></li>
|
||||
</ul>
|
||||
|
||||
<div class="byline">
|
||||
<span>authored by</span>
|
||||
<a tabindex="-1" aria-hidden="true" href="/~gioele"><img srcset="/avatars/gioele-16.png 1x, /avatars/gioele-32.png 2x" class="avatar" alt="gioele avatar" loading="lazy" decoding="async" src="/avatars/gioele-16.png" width="16" height="16"></a>
|
||||
<a tabindex="-1" aria-hidden="true" href="/~gioele"><img srcset="/avatars/gioele-16.png 1x, /avatars/gioele-32.png 2x" class="avatar" alt="" loading="lazy" decoding="async" src="/avatars/gioele-16.png" width="16" height="16"></a>
|
||||
<a class="user_is_author" href="/~gioele">gioele</a>
|
||||
|
||||
<time title="2022-07-22 12:06:59" datetime="2022-07-22 12:06:59" data-at-unix="1658509619">3 years ago</time>
|
||||
@@ -164,9 +164,9 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
<li class="comments_subtree">
|
||||
|
||||
|
||||
<input id="comment_folder_ncdsfc"
|
||||
class="comment_folder_button" type="checkbox"
|
||||
>
|
||||
<input id="comment_folder_ncdsfc"
|
||||
class="comment_folder_button" type="checkbox"
|
||||
>
|
||||
|
||||
<div id="c_ncdsfc"
|
||||
data-shortid="ncdsfc"
|
||||
@@ -179,7 +179,7 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
|
||||
<div class="voters">
|
||||
<label for="comment_folder_ncdsfc" class="comment_folder"></label>
|
||||
<a class="upvoter" title="18" href="/login">18</a>
|
||||
<a class="upvoter" title="18" href="/login">18</a>
|
||||
</div>
|
||||
|
||||
<div class="details">
|
||||
@@ -188,7 +188,7 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
|
||||
|
||||
<span class="">
|
||||
<a tabindex="-1" aria-hidden="true" href="/~dpercy"><img srcset="/avatars/dpercy-16.png 1x, /avatars/dpercy-32.png 2x" class="avatar" alt="dpercy avatar" loading="lazy" decoding="async" src="/avatars/dpercy-16.png" width="16" height="16"></a>
|
||||
<a tabindex="-1" aria-hidden="true" href="/~dpercy"><img srcset="/avatars/dpercy-16.png 1x, /avatars/dpercy-32.png 2x" class="avatar" alt="" loading="lazy" decoding="async" src="/avatars/dpercy-16.png" width="16" height="16"></a>
|
||||
<a href="/~dpercy">dpercy</a>
|
||||
|
||||
|
||||
@@ -226,9 +226,9 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
<li class="comments_subtree">
|
||||
|
||||
|
||||
<input id="comment_folder_m3wyu5"
|
||||
class="comment_folder_button" type="checkbox"
|
||||
>
|
||||
<input id="comment_folder_m3wyu5"
|
||||
class="comment_folder_button" type="checkbox"
|
||||
>
|
||||
|
||||
<div id="c_m3wyu5"
|
||||
data-shortid="m3wyu5"
|
||||
@@ -241,7 +241,7 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
|
||||
<div class="voters">
|
||||
<label for="comment_folder_m3wyu5" class="comment_folder"></label>
|
||||
<a class="upvoter" title="8" href="/login">8</a>
|
||||
<a class="upvoter" title="8" href="/login">8</a>
|
||||
</div>
|
||||
|
||||
<div class="details">
|
||||
@@ -250,7 +250,7 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
|
||||
|
||||
<span class="">
|
||||
<a tabindex="-1" aria-hidden="true" href="/~friendlysock"><img srcset="/avatars/friendlysock-16.png 1x, /avatars/friendlysock-32.png 2x" class="avatar" alt="friendlysock avatar" loading="lazy" decoding="async" src="/avatars/friendlysock-16.png" width="16" height="16"></a>
|
||||
<a tabindex="-1" aria-hidden="true" href="/~friendlysock"><img srcset="/avatars/friendlysock-16.png 1x, /avatars/friendlysock-32.png 2x" class="avatar" alt="" loading="lazy" decoding="async" src="/avatars/friendlysock-16.png" width="16" height="16"></a>
|
||||
<a class="inactive_user" aria-label="friendlysock - Inactive user" href="/~friendlysock">friendlysock</a>
|
||||
|
||||
|
||||
@@ -282,9 +282,9 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
<li class="comments_subtree">
|
||||
|
||||
|
||||
<input id="comment_folder_pcvbcd"
|
||||
class="comment_folder_button" type="checkbox"
|
||||
>
|
||||
<input id="comment_folder_pcvbcd"
|
||||
class="comment_folder_button" type="checkbox"
|
||||
>
|
||||
|
||||
<div id="c_pcvbcd"
|
||||
data-shortid="pcvbcd"
|
||||
@@ -297,7 +297,7 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
|
||||
<div class="voters">
|
||||
<label for="comment_folder_pcvbcd" class="comment_folder"></label>
|
||||
<a class="upvoter" title="2" href="/login">2</a>
|
||||
<a class="upvoter" title="2" href="/login">2</a>
|
||||
</div>
|
||||
|
||||
<div class="details">
|
||||
@@ -306,7 +306,7 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
|
||||
|
||||
<span class="">
|
||||
<a tabindex="-1" aria-hidden="true" href="/~gioele"><img srcset="/avatars/gioele-16.png 1x, /avatars/gioele-32.png 2x" class="avatar" alt="gioele avatar" loading="lazy" decoding="async" src="/avatars/gioele-16.png" width="16" height="16"></a>
|
||||
<a tabindex="-1" aria-hidden="true" href="/~gioele"><img srcset="/avatars/gioele-16.png 1x, /avatars/gioele-32.png 2x" class="avatar" alt="" loading="lazy" decoding="async" src="/avatars/gioele-16.png" width="16" height="16"></a>
|
||||
<a class="user_is_author user_is_submitter" aria-label="gioele - Submitter" href="/~gioele">gioele</a>
|
||||
|
||||
|
||||
@@ -348,9 +348,9 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
<li class="comments_subtree">
|
||||
|
||||
|
||||
<input id="comment_folder_9vyyu5"
|
||||
class="comment_folder_button" type="checkbox"
|
||||
>
|
||||
<input id="comment_folder_9vyyu5"
|
||||
class="comment_folder_button" type="checkbox"
|
||||
>
|
||||
|
||||
<div id="c_9vyyu5"
|
||||
data-shortid="9vyyu5"
|
||||
@@ -363,7 +363,7 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
|
||||
<div class="voters">
|
||||
<label for="comment_folder_9vyyu5" class="comment_folder"></label>
|
||||
<a class="upvoter" title="5" href="/login">5</a>
|
||||
<a class="upvoter" title="5" href="/login">5</a>
|
||||
</div>
|
||||
|
||||
<div class="details">
|
||||
@@ -372,7 +372,7 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
|
||||
|
||||
<span class="">
|
||||
<a tabindex="-1" aria-hidden="true" href="/~kghose"><img srcset="/avatars/kghose-16.png 1x, /avatars/kghose-32.png 2x" class="avatar" alt="kghose avatar" loading="lazy" decoding="async" src="/avatars/kghose-16.png" width="16" height="16"></a>
|
||||
<a tabindex="-1" aria-hidden="true" href="/~kghose"><img srcset="/avatars/kghose-16.png 1x, /avatars/kghose-32.png 2x" class="avatar" alt="" loading="lazy" decoding="async" src="/avatars/kghose-16.png" width="16" height="16"></a>
|
||||
<a href="/~kghose">kghose</a>
|
||||
|
||||
|
||||
@@ -405,9 +405,9 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
<li class="comments_subtree">
|
||||
|
||||
|
||||
<input id="comment_folder_owddle"
|
||||
class="comment_folder_button" type="checkbox"
|
||||
>
|
||||
<input id="comment_folder_owddle"
|
||||
class="comment_folder_button" type="checkbox"
|
||||
>
|
||||
|
||||
<div id="c_owddle"
|
||||
data-shortid="owddle"
|
||||
@@ -420,7 +420,7 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
|
||||
<div class="voters">
|
||||
<label for="comment_folder_owddle" class="comment_folder"></label>
|
||||
<a class="upvoter" title="7" href="/login">7</a>
|
||||
<a class="upvoter" title="7" href="/login">7</a>
|
||||
</div>
|
||||
|
||||
<div class="details">
|
||||
@@ -429,7 +429,7 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
|
||||
|
||||
<span class="">
|
||||
<a tabindex="-1" aria-hidden="true" href="/~gioele"><img srcset="/avatars/gioele-16.png 1x, /avatars/gioele-32.png 2x" class="avatar" alt="gioele avatar" loading="lazy" decoding="async" src="/avatars/gioele-16.png" width="16" height="16"></a>
|
||||
<a tabindex="-1" aria-hidden="true" href="/~gioele"><img srcset="/avatars/gioele-16.png 1x, /avatars/gioele-32.png 2x" class="avatar" alt="" loading="lazy" decoding="async" src="/avatars/gioele-16.png" width="16" height="16"></a>
|
||||
<a class="user_is_author user_is_submitter" aria-label="gioele - Submitter" href="/~gioele">gioele</a>
|
||||
|
||||
|
||||
@@ -466,9 +466,9 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
<li class="comments_subtree">
|
||||
|
||||
|
||||
<input id="comment_folder_lqqn3a"
|
||||
class="comment_folder_button" type="checkbox"
|
||||
>
|
||||
<input id="comment_folder_lqqn3a"
|
||||
class="comment_folder_button" type="checkbox"
|
||||
>
|
||||
|
||||
<div id="c_lqqn3a"
|
||||
data-shortid="lqqn3a"
|
||||
@@ -481,7 +481,7 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
|
||||
<div class="voters">
|
||||
<label for="comment_folder_lqqn3a" class="comment_folder"></label>
|
||||
<a class="upvoter" title="2" href="/login">2</a>
|
||||
<a class="upvoter" title="2" href="/login">2</a>
|
||||
</div>
|
||||
|
||||
<div class="details">
|
||||
@@ -490,7 +490,7 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
|
||||
|
||||
<span class="">
|
||||
<a tabindex="-1" aria-hidden="true" href="/~kghose"><img srcset="/avatars/kghose-16.png 1x, /avatars/kghose-32.png 2x" class="avatar" alt="kghose avatar" loading="lazy" decoding="async" src="/avatars/kghose-16.png" width="16" height="16"></a>
|
||||
<a tabindex="-1" aria-hidden="true" href="/~kghose"><img srcset="/avatars/kghose-16.png 1x, /avatars/kghose-32.png 2x" class="avatar" alt="" loading="lazy" decoding="async" src="/avatars/kghose-16.png" width="16" height="16"></a>
|
||||
<a href="/~kghose">kghose</a>
|
||||
|
||||
|
||||
@@ -531,9 +531,9 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
<li class="comments_subtree">
|
||||
|
||||
|
||||
<input id="comment_folder_7b0jgw"
|
||||
class="comment_folder_button" type="checkbox"
|
||||
>
|
||||
<input id="comment_folder_7b0jgw"
|
||||
class="comment_folder_button" type="checkbox"
|
||||
>
|
||||
|
||||
<div id="c_7b0jgw"
|
||||
data-shortid="7b0jgw"
|
||||
@@ -546,7 +546,7 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
|
||||
<div class="voters">
|
||||
<label for="comment_folder_7b0jgw" class="comment_folder"></label>
|
||||
<a class="upvoter" title="4" href="/login">4</a>
|
||||
<a class="upvoter" title="4" href="/login">4</a>
|
||||
</div>
|
||||
|
||||
<div class="details">
|
||||
@@ -555,7 +555,7 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
|
||||
|
||||
<span class="">
|
||||
<a tabindex="-1" aria-hidden="true" href="/~FeepingCreature"><img srcset="/avatars/FeepingCreature-16.png 1x, /avatars/FeepingCreature-32.png 2x" class="avatar" alt="FeepingCreature avatar" loading="lazy" decoding="async" src="/avatars/FeepingCreature-16.png" width="16" height="16"></a>
|
||||
<a tabindex="-1" aria-hidden="true" href="/~FeepingCreature"><img srcset="/avatars/FeepingCreature-16.png 1x, /avatars/FeepingCreature-32.png 2x" class="avatar" alt="" loading="lazy" decoding="async" src="/avatars/FeepingCreature-16.png" width="16" height="16"></a>
|
||||
<a href="/~FeepingCreature">FeepingCreature</a>
|
||||
|
||||
|
||||
@@ -591,9 +591,9 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
<li class="comments_subtree">
|
||||
|
||||
|
||||
<input id="comment_folder_ei3nck"
|
||||
class="comment_folder_button" type="checkbox"
|
||||
>
|
||||
<input id="comment_folder_ei3nck"
|
||||
class="comment_folder_button" type="checkbox"
|
||||
>
|
||||
|
||||
<div id="c_ei3nck"
|
||||
data-shortid="ei3nck"
|
||||
@@ -606,7 +606,7 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
|
||||
<div class="voters">
|
||||
<label for="comment_folder_ei3nck" class="comment_folder"></label>
|
||||
<a class="upvoter" title="2" href="/login">2</a>
|
||||
<a class="upvoter" title="2" href="/login">2</a>
|
||||
</div>
|
||||
|
||||
<div class="details">
|
||||
@@ -615,7 +615,7 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
|
||||
|
||||
<span class="">
|
||||
<a tabindex="-1" aria-hidden="true" href="/~FRIGN"><img srcset="/avatars/FRIGN-16.png 1x, /avatars/FRIGN-32.png 2x" class="avatar" alt="FRIGN avatar" loading="lazy" decoding="async" src="/avatars/FRIGN-16.png" width="16" height="16"></a>
|
||||
<a tabindex="-1" aria-hidden="true" href="/~FRIGN"><img srcset="/avatars/FRIGN-16.png 1x, /avatars/FRIGN-32.png 2x" class="avatar" alt="" loading="lazy" decoding="async" src="/avatars/FRIGN-16.png" width="16" height="16"></a>
|
||||
<a href="/~FRIGN">FRIGN</a>
|
||||
|
||||
|
||||
@@ -670,9 +670,9 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
<li class="comments_subtree">
|
||||
|
||||
|
||||
<input id="comment_folder_4l8mzk"
|
||||
class="comment_folder_button" type="checkbox"
|
||||
>
|
||||
<input id="comment_folder_4l8mzk"
|
||||
class="comment_folder_button" type="checkbox"
|
||||
>
|
||||
|
||||
<div id="c_4l8mzk"
|
||||
data-shortid="4l8mzk"
|
||||
@@ -685,7 +685,7 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
|
||||
<div class="voters">
|
||||
<label for="comment_folder_4l8mzk" class="comment_folder"></label>
|
||||
<a class="upvoter" title="2" href="/login">2</a>
|
||||
<a class="upvoter" title="2" href="/login">2</a>
|
||||
</div>
|
||||
|
||||
<div class="details">
|
||||
@@ -694,7 +694,7 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
|
||||
|
||||
<span class="">
|
||||
<a tabindex="-1" aria-hidden="true" href="/~feoh"><img srcset="/avatars/feoh-16.png 1x, /avatars/feoh-32.png 2x" class="avatar" alt="feoh avatar" loading="lazy" decoding="async" src="/avatars/feoh-16.png" width="16" height="16"></a>
|
||||
<a tabindex="-1" aria-hidden="true" href="/~feoh"><img srcset="/avatars/feoh-16.png 1x, /avatars/feoh-32.png 2x" class="avatar" alt="" loading="lazy" decoding="async" src="/avatars/feoh-16.png" width="16" height="16"></a>
|
||||
<a href="/~feoh">feoh</a>
|
||||
|
||||
|
||||
@@ -726,9 +726,9 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
<li class="comments_subtree">
|
||||
|
||||
|
||||
<input id="comment_folder_qy0l9k"
|
||||
class="comment_folder_button" type="checkbox"
|
||||
>
|
||||
<input id="comment_folder_qy0l9k"
|
||||
class="comment_folder_button" type="checkbox"
|
||||
>
|
||||
|
||||
<div id="c_qy0l9k"
|
||||
data-shortid="qy0l9k"
|
||||
@@ -741,7 +741,7 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
|
||||
<div class="voters">
|
||||
<label for="comment_folder_qy0l9k" class="comment_folder"></label>
|
||||
<a class="upvoter" title="5" href="/login">5</a>
|
||||
<a class="upvoter" title="5" href="/login">5</a>
|
||||
</div>
|
||||
|
||||
<div class="details">
|
||||
@@ -750,7 +750,7 @@ An example, as of 2022-07-22 17:00 UTC, is <https://lobste.rs/s/ekvqcf/random
|
||||
|
||||
|
||||
<span class="">
|
||||
<a tabindex="-1" aria-hidden="true" href="/~pushcx"><img srcset="/avatars/pushcx-16.png 1x, /avatars/pushcx-32.png 2x" class="avatar" alt="pushcx avatar" loading="lazy" decoding="async" src="/avatars/pushcx-16.png" width="16" height="16"></a>
|
||||
<a tabindex="-1" aria-hidden="true" href="/~pushcx"><img srcset="/avatars/pushcx-16.png 1x, /avatars/pushcx-32.png 2x" class="avatar" alt="" loading="lazy" decoding="async" src="/avatars/pushcx-16.png" width="16" height="16"></a>
|
||||
<a href="/~pushcx">pushcx</a>
|
||||
|
||||
|
||||
|
||||
+9
-9
@@ -45,15 +45,7 @@ private fun Element.toComment(parentComment: String?): Comment {
|
||||
shortId = attr("data-shortid"),
|
||||
comment = selectFirst("div.comment_text")?.html().orEmpty(),
|
||||
url = selectFirst("div.byline a[href^=/c/]")?.absUrl("href").orEmpty(),
|
||||
score =
|
||||
children()
|
||||
.firstOrNull { it.hasClass("voters") }
|
||||
?.children()
|
||||
?.firstOrNull { it.hasClass("upvoter") }
|
||||
?.text()
|
||||
?.trim()
|
||||
?.takeUnless { it == "~" }
|
||||
?.toIntOrNull() ?: 1,
|
||||
score = parseCommentScore(),
|
||||
timestamp = timestamp.toEpochSeconds(),
|
||||
edited = isEdited,
|
||||
parentComment = parentComment,
|
||||
@@ -67,6 +59,14 @@ private fun Element.toComment(parentComment: String?): Comment {
|
||||
)
|
||||
}
|
||||
|
||||
private fun Element.parseCommentScore(): Int {
|
||||
val upvoter = selectFirst("div.voters .upvoter") ?: return 1
|
||||
val rawScore =
|
||||
listOf(upvoter.attr("title").trim(), upvoter.text().trim()).firstOrNull { it.isNotEmpty() }
|
||||
?: return 1
|
||||
return if (rawScore == "~") 1 else rawScore.toIntOrNull() ?: 1
|
||||
}
|
||||
|
||||
private fun String.toEpochSeconds(): Long {
|
||||
return when {
|
||||
isBlank() -> 0L
|
||||
|
||||
+39
@@ -130,4 +130,43 @@ class RealLobstersHtmlParserJvmTest {
|
||||
|
||||
kotlin.test.assertEquals(1, details.comments.single().score)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun commentScoresUseUpvoterTitleWhenVisibleTextIsOmitted() {
|
||||
val html =
|
||||
"""
|
||||
<ol class="stories">
|
||||
<li class="story" data-shortid="story1">
|
||||
<span class="link h-cite"><a href="/s/story1/test">Test story</a></span>
|
||||
<div class="byline">
|
||||
<a class="u-author" href="/~/submitter">submitter</a>
|
||||
<time data-at-unix="1710000000"></time>
|
||||
</div>
|
||||
</li>
|
||||
</ol>
|
||||
<ol class="comments">
|
||||
<li class="comments_subtree">
|
||||
<div class="comment" data-shortid="abc123">
|
||||
<div class="voters">
|
||||
<label for="comment_folder_abc123" class="comment_folder"></label>
|
||||
<a class="upvoter" title="12" href="/login"></a>
|
||||
</div>
|
||||
<div class="details">
|
||||
<div class="byline">
|
||||
<a href="/~/author">author</a>
|
||||
<a href="/c/abc123"><time data-at-unix="1710000000"></time></a>
|
||||
</div>
|
||||
<div class="comment_text"><p>Hello</p></div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ol>
|
||||
"""
|
||||
.trimIndent()
|
||||
val service = LobstersParserServiceImpl()
|
||||
|
||||
val details = service.parsePostDetails(html)
|
||||
|
||||
kotlin.test.assertEquals(12, details.comments.single().score)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user