Skip to content

Commit

Permalink
- Fix UTF-8 comments from the CLI version. (closes #442)
Browse files Browse the repository at this point in the history
  • Loading branch information
trizen committed Jan 21, 2025
1 parent baf7c8e commit 2cb70fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 9 additions & 3 deletions bin/youtube-viewer
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/perl

# Copyright (C) 2010-2024 Trizen <echo dHJpemVuQHByb3Rvbm1haWwuY29tCg== | base64 -d>.
# Copyright (C) 2010-2025 Trizen <echo dHJpemVuQHByb3Rvbm1haWwuY29tCg== | base64 -d>.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of either: the GNU General Public License as published
Expand All @@ -15,7 +15,7 @@
#-------------------------------------------------------
# youtube-viewer
# Created on: 02 June 2010
# Latest edit on: 25 August 2024
# Latest edit on: 21 January 2025
# https://github.com/trizen/youtube-viewer
#-------------------------------------------------------

Expand Down Expand Up @@ -3177,7 +3177,13 @@ sub print_comments {
warn colored("\n[!] Editor exited with a non-zero code. Unable to continue!", 'bold red') . "\n";
}
else {
my $comment = do { local (@ARGV, $/) = $filename; <> };
my $comment = do {
open(my $fh, '<:utf8', $filename)
or warn colored("\n[!] Your comment has NOT been posted!", 'bold red') . "\n";
local $/;
<$fh>;
};

$comment =~ s/[^\s[:^cntrl:]]+//g; # remove control characters

if (length($comment) and $yv_obj->comment_to_video_id($comment, $videoID)) {
Expand Down
3 changes: 1 addition & 2 deletions lib/WWW/YoutubeViewer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,7 @@ sub _send_request {
if (defined($content)) {
$req->content_type('application/json; charset=UTF-8');
$req->header('Content-Length' => length($content));
use Encode;
$req->content(Encode::encode 'UTF-8', $content);
$req->content($content);
}

$self->{lwp}->request($req);
Expand Down

0 comments on commit 2cb70fc

Please sign in to comment.