microsoft / azurelinux

Linux OS for Azure 1P services and edge appliances
MIT License
4.31k stars 547 forks source link

how to install perl-URI-Encode on CBL Mariner #6166

Open pramenku opened 1 year ago

pramenku commented 1 year ago

Unable to find perl-URI-Encode package for CBL mariner How to get it ?

mfrw commented 1 year ago

We do not ship perl-URI-Encode for CBL-Mariner. What is your usecase ? Can you please elaborate.

zcobol commented 1 year ago

@pramenku there's perl-URI package available. See details at https://github.com/microsoft/CBL-Mariner/blob/2.0/SPECS/perl-URI/perl-URI.spec

mfrw commented 1 year ago

@pramenku there's perl-URI package available. See details at https://github.com/microsoft/CBL-Mariner/blob/2.0/SPECS/perl-URI/perl-URI.spec

I think perl-URI & perl-URI-Encode are two different specs/packages IMHO.

pramenku commented 1 year ago

perl-URI

Actually, we need "perl-URI-Encode"

Usecase: perl-URI-Encode needed by hip-devel

hip-devel is HIP package which needs "perl-URI-Encode" , defined at below line. It's mandatory to have it to install rocm driver.

hip-devel

elsaco commented 1 year ago

@pramenku until CBL-Mariner team adds the package installing it manually is trivial. Use a source package from Fedora and build locally. Here's the spec from Fedora 38 used for testing on CBL-Mariner 2.0:

perl-URI-Encode.spec %global cpan_version v1.1.1 Name: perl-URI-Encode Version: %(echo '%{cpan_version}' | tr -d 'v') Release: 21%{?dist} Summary: Percent encoding/decoding for URIs License: GPL+ or Artistic URL: https://metacpan.org/release/URI-Encode Source0: https://cpan.metacpan.org/modules/by-module/URI/URI-Encode-%{cpan_version}.tar.gz BuildArch: noarch # Build BuildRequires: coreutils BuildRequires: perl-generators BuildRequires: perl-interpreter BuildRequires: perl(Module::Build) >= 0.38 # Run-time BuildRequires: perl(base) BuildRequires: perl(Carp) BuildRequires: perl(Encode) >= 2.12 BuildRequires: perl(Exporter) BuildRequires: perl(strict) # Test Suite BuildRequires: perl(Test::More) >= 0.88 BuildRequires: perl(warnings) # Dependencies Requires: perl(Encode) >= 2.12 # Drop under-specified dependencies %{?perl_default_filter} %global __requires_exclude %{?__requires_exclude:__requires_exclude|}^perl\\(Encode\\)$ %description This module provides a method to encode strings (mainly URLs) into a format which can be pasted into a plain text emails, and that those links are 'click-able' by the person reading that email. This can be accomplished by NOT encoding the reserved characters. %prep %setup -q -n URI-Encode-%{cpan_version} %build perl Build.PL --installdirs=vendor ./Build %install ./Build install --destdir=%{buildroot} --create_packlist=0 %{_fixperms} -c %{buildroot} %check ./Build test %files %license LICENSE %doc Changes README %{perl_vendorlib}/URI/ %{_mandir}/man3/URI::Encode.3* %changelog * Wed Sep 06 2023 Elsaco - 1.1.1-21 - Local rebuild * Fri Jan 20 2023 Fedora Release Engineering - 1.1.1-20 - Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild * Fri Jul 22 2022 Fedora Release Engineering - 1.1.1-19 - Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild * Tue May 31 2022 Jitka Plesnikova - 1.1.1-18 - Perl 5.36 rebuild * Tue Jul 27 2021 Fedora Release Engineering - 1.1.1-17 - Second attempt - Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild * Fri May 21 2021 Jitka Plesnikova - 1.1.1-16 - Perl 5.34 rebuild * Wed Jan 27 2021 Fedora Release Engineering - 1.1.1-15 - Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild * Tue Jul 28 2020 Fedora Release Engineering - 1.1.1-14 - Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild * Tue Jun 23 2020 Jitka Plesnikova - 1.1.1-13 - Perl 5.32 rebuild * Thu Jan 30 2020 Fedora Release Engineering - 1.1.1-12 - Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild * Sun Nov 10 2019 Paul Howarth - 1.1.1-11 - Spec tidy-up - Classify buildreqs by usage - Fix permissions verbosely - Make %%files list more explicit * Fri Jul 26 2019 Fedora Release Engineering - 1.1.1-10 - Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild * Fri May 31 2019 Jitka Plesnikova - 1.1.1-9 - Perl 5.30 rebuild * Sat Feb 02 2019 Fedora Release Engineering - 1.1.1-8 - Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild * Fri Jul 13 2018 Fedora Release Engineering - 1.1.1-7 - Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild * Thu Jun 28 2018 Jitka Plesnikova - 1.1.1-6 - Perl 5.28 rebuild * Fri Feb 09 2018 Fedora Release Engineering - 1.1.1-5 - Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild * Thu Jul 27 2017 Fedora Release Engineering - 1.1.1-4 - Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Mass_Rebuild * Sun Jun 04 2017 Jitka Plesnikova - 1.1.1-3 - Perl 5.26 rebuild * Sat Feb 11 2017 Fedora Release Engineering - 1.1.1-2 - Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild * Thu Jun 16 2016 Jitka Plesnikova - 1.1.1-1 - 1.1.1 bump * Sun May 15 2016 Jitka Plesnikova - 1.0.1-3 - Perl 5.24 rebuild * Thu Feb 04 2016 Fedora Release Engineering - 1.0.1-2 - Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild * Wed Aug 26 2015 Jitka Plesnikova - 1.0.1-1 - 1.0.1 bump * Thu Jun 18 2015 Fedora Release Engineering - 0.09-3 - Rebuilt for https://fedoraproject.org/wiki/Fedora_23_Mass_Rebuild * Fri Jun 05 2015 Jitka Plesnikova - 0.09-2 - Perl 5.22 rebuild * Wed Oct 01 2014 David Dick - 0.09-1 - Initial release

or just add Encode.pm to /usr/share/perl5/vendor_perl/URI/. It's a tiny module:

package URI::Encode;

#######################
# LOAD MODULES
#######################
use strict;
use warnings FATAL => 'all';

use 5.008001;
use Encode qw();
use Carp qw(croak carp);

#######################
# VERSION
#######################
our $VERSION = '1.1.1';

#######################
# EXPORT
#######################
use base qw(Exporter);
our (@EXPORT_OK);

@EXPORT_OK = qw(uri_encode uri_decode);

#######################
# SETTINGS
#######################

# Reserved characters
my $reserved_re
  = qr{([^a-zA-Z0-9\-\_\.\~\!\*\'\(\)\;\:\@\&\=\+\$\,\/\?\#\[\]\%])}x;

# Un-reserved characters
my $unreserved_re = qr{([^a-zA-Z0-9\Q-_.~\E\%])}x;

# Encoded character set
my $encoded_chars = qr{%([a-fA-F0-9]{2})}x;

#######################
# CONSTRUCTOR
#######################
sub new {
    my ( $class, @in ) = @_;

    # Check Input
    my $defaults = {

        #   this module, unlike URI::Escape,
        #   does not encode reserved characters
        encode_reserved => 0,

        #   Allow Double encoding?
        #   defaults to YES
        double_encode => 1,
    };

    my $input = {};
    if   ( ref $in[0] eq 'HASH' ) { $input = $in[0]; }
    else                          { $input = {@in}; }

    # Set options
    my $options = {

        # Defaults
        %{$defaults},

        # Input
        %{$input},

        # Encoding Map
        enc_map =>
          { ( map { chr($_) => sprintf( "%%%02X", $_ ) } ( 0 ... 255 ) ) },

        # Decoding Map
        dec_map =>
          { ( map { sprintf( "%02X", $_ ) => chr($_) } ( 0 ... 255 ) ), },
    };

    # Return
    my $self = bless $options, $class;
  return $self;
} ## end sub new

#######################
# ENCODE
#######################
sub encode {
    my ( $self, $data, $options ) = @_;

    # Check for data
    # Allow to be '0'
  return unless defined $data;

    my $enc_res       = $self->{encode_reserved};
    my $double_encode = $self->{double_encode};

    if ( defined $options ) {
        if ( ref $options eq 'HASH' ) {
            $enc_res = $options->{encode_reserved}
              if exists $options->{encode_reserved};
            $double_encode = $options->{double_encode}
              if exists $options->{double_encode};
        } ## end if ( ref $options eq 'HASH')
        else {
            $enc_res = $options;
        }
    } ## end if ( defined $options )

    # UTF-8 encode
    $data = Encode::encode( 'utf-8-strict', $data );

    # Encode a literal '%'
    if ($double_encode) { $data =~ s{(\%)}{$self->_get_encoded_char($1)}gex; }
    else { $data =~ s{(\%)(.*)}{$self->_encode_literal_percent($1, $2)}gex; }

    # Percent Encode
    if ($enc_res) {
        $data =~ s{$unreserved_re}{$self->_get_encoded_char($1)}gex;
    }
    else {
        $data =~ s{$reserved_re}{$self->_get_encoded_char($1)}gex;
    }

    # Done
  return $data;
} ## end sub encode

#######################
# DECODE
#######################
sub decode {
    my ( $self, $data ) = @_;

    # Check for data
    # Allow to be '0'
  return unless defined $data;

    # Percent Decode
    $data =~ s{$encoded_chars}{ $self->_get_decoded_char($1) }gex;

  return $data;
} ## end sub decode

#######################
# EXPORTED FUNCTIONS
#######################

# Encoder
sub uri_encode { return __PACKAGE__->new()->encode(@_); }

# Decoder
sub uri_decode { return __PACKAGE__->new()->decode(@_); }

#######################
# INTERNAL
#######################

sub _get_encoded_char {
    my ( $self, $char ) = @_;
  return $self->{enc_map}->{$char} if exists $self->{enc_map}->{$char};
  return $char;
} ## end sub _get_encoded_char

sub _encode_literal_percent {
    my ( $self, $char, $post ) = @_;

  return $self->_get_encoded_char($char) if not defined $post;

    my $return_char;
    if ( $post =~ m{^([a-fA-F0-9]{2})}x ) {
        if ( exists $self->{dec_map}->{$1} ) {
            $return_char = join( '', $char, $post );
        }
    } ## end if ( $post =~ m{^([a-fA-F0-9]{2})}x)

    $return_char ||= join( '', $self->_get_encoded_char($char), $post );
  return $return_char;
} ## end sub _encode_literal_percent

sub _get_decoded_char {
    my ( $self, $char ) = @_;
  return $self->{dec_map}->{ uc($char) }
      if exists $self->{dec_map}->{ uc($char) };
  return $char;
} ## end sub _get_decoded_char

#######################
1;

__END__

#######################
# POD SECTION
#######################
=pod

=head1 NAME

URI::Encode - Simple percent Encoding/Decoding

=for html <a href="https://travis-ci.org/mithun/perl-uri-encode"><img src="https://travis-ci.org/mithun/perl-uri-encode.svg?branch=master"></a>

=head1 SYNOPSIS

    # OOP Interface
    use URI::Encode;
    my $uri     = URI::Encode->new( { encode_reserved => 0 } );
    my $encoded = $uri->encode($data);
    my $decoded = $uri->decode($encoded);

    # Functional
    use URI::Encode qw(uri_encode uri_decode);
    my $encoded = uri_encode($data);
    my $decoded = uri_decode($encoded);

=head1 DESCRIPTION

This modules provides simple URI (Percent) encoding/decoding

The main purpose of this module (at least for me) was to provide an
easy method to encode strings (mainly URLs) into a format which can be
pasted into a plain text emails, and that those links are 'click-able'
by the person reading that email. This can be accomplished by NOT
encoding the reserved characters.

This module can also be useful when using L<HTTP::Tiny> to ensure the
URLs are properly escaped.

B<This module does not encode reserved characters by default>. If you
are looking for speed and want to encode reserved characters, use
L<URI::Escape::XS>

See L<this
script|https://github.com/mithun/perl-uri-encode/raw/master/.author/benchmark.pl>
for a comparison on encoding results and performance.

=head1 METHODS

=head2 new()

Creates a new object, no arguments are required

    my $encoder = URI::Encode->new(\%options);

The following options can be passed to the constructor

=over

=item encode_reserved

    my $encoder = URI::Encode->new({encode_reserved => 0});

If true, L</"Reserved Characters"> are also encoded. Defaults to false.

=item double_encode

    my $encoder = URI::Encode->new({double_encode => 1});

If false, characters that are already percent-encoded will not be
encoded again. Defaults to true.

    my $encoder = URI::Encode->new({double_encode => 0});
    print $encoder->encode('http://perl.com/foo%20bar'); # prints http://perl.com/foo%20bar

=back

=head2 C<encode($url, \%options)>

This method encodes the URL provided. The C<$url> provided is first
converted into UTF-8 before percent encoding. Options set in the
constructor, or defaults, can be overridden by passing them as the
(optional) second argument. Options passed must be a hashref.

    $uri->encode("http://perl.com/foo bar");
    $uri->encode( "http://perl.com/foo bar", { encode_reserved => 1 } );

=head2 C<decode($url)>

This method decodes a 'percent' encoded URL. If you had encoded the URL
using this module (or any other method), chances are that the URL was
converted to UTF-8 before 'percent' encoding. Be sure to check the
format and convert back if required.

    $uri->decode("http%3A%2F%2Fperl.com%2Ffoo%20bar");

=head1 EXPORTED FUNCTIONS

The following functions are exported upon request. This provides a
non-OOP interface

=over

=item C<uri_encode($url, \%options)>

=item C<uri_decode($url)>

=back

=head1 CHARACTER CLASSES

=head2 Reserved Characters

The following characters are considered as reserved (L<RFC
3986|http://tools.ietf.org/html/rfc3986>). They will be encoded only if
requested.

     ! * ' ( ) ; : @ & = + $ , / ? # [ ]

=head2 Unreserved Characters

The following characters are considered as Unreserved. They will not be
encoded

    a-z
    A-Z
    0-9
    - _ . ~

=head1 DEPENDENCIES

L<Encode>

=head1 ACKNOWLEDGEMENTS

Gisle Aas for L<URI::Escape>

David Nicol for L<Tie::UrlEncoder>

=head1 SEE ALSO

L<RFC 3986|http://tools.ietf.org/html/rfc3986>

L<URI::Escape>

L<URI::Escape::XS>

L<URI::Escape::JavaScript>

L<Tie::UrlEncoder>

=head1 BUGS AND LIMITATIONS

Please report any bugs or feature requests at
L<https://github.com/mithun/perl-uri-encode/issues>

=head1 AUTHOR

Mithun Ayachit C<mithun@cpan.org>

=head1 LICENSE AND COPYRIGHT

Copyright (c) 2014, Mithun Ayachit. All rights reserved.

This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself. See L<perlartistic>.

=cut
pramenku commented 1 year ago

hip-devel

Thanks @elsaco , Actually, I have tried it already but did not work.

hip-devel is expecting as package also installed , means "dnf info perl-URI-Encode" should show the info like perl-File-BaseDir is showing below. We need to tweak on the system so dnf show as package installed.

dnf info perl-File-BaseDir Last metadata expiration check: 1 day, 22:23:03 ago on Tue Sep 5 09:00:57 2023. Installed Packages Name : perl-File-BaseDir Version : 0.08 Release : 9.cm2 Architecture : noarch Size : 17 k Source : perl-File-BaseDir-0.08-9.cm2.src.rpm Repository : @System From repo : mariner-official-extended Summary : Use the Freedesktop.org base directory specification URL : https://metacpan.org/release/File-BaseDir License : GPL+ or Artistic Description : This module can be used to find directories and files as specified by the : Freedesktop.org Base Directory Specification. This specifications gives a : mechanism to locate directories for configuration, application data and : cache data. It is suggested that desktop applications for e.g. the Gnome, : KDE or Xfce platforms follow this layout. However, the same layout can just : as well be used for non-GUI applications.

elsaco commented 1 year ago

@pramenku I understand your frustration. Hopefully CBL-Mariner team takes notice. In the meantime I added the RPM and SRPM to https://github.com/elsaco/cbl-mariner-rpms. You could rebuild the srpm on your system or use the binary package. Verify contents fist!

Output of rpm -qi perl-URI-Encode:

Name        : perl-URI-Encode
Version     : 1.1.1
Release     : 21.cm2
Architecture: noarch
Install Date: Wed Sep  6 19:27:10 2023
Group       : Unspecified
Size        : 36127
License     : GPL+ or Artistic
Signature   : (none)
Source RPM  : perl-URI-Encode-1.1.1-21.cm2.src.rpm
Build Date  : Wed Sep  6 19:16:49 2023
Build Host  : redmon
URL         : https://metacpan.org/release/URI-Encode
Summary     : Percent encoding/decoding for URIs
Description :
This module provides a method to encode strings (mainly URLs) into a format
which can be pasted into a plain text emails, and that those links are
'click-able' by the person reading that email.  This can be accomplished by NOT
encoding the reserved characters.

This will satisfy your package dependencies.

pramenku commented 1 year ago

@pramenku I understand your frustration. Hopefully CBL-Mariner team takes notice. In the meantime I added the RPM and SRPM to https://github.com/elsaco/cbl-mariner-rpms. You could rebuild the srpm on your system or use the binary package. Verify contents fist!

Output of rpm -qi perl-URI-Encode:

Name        : perl-URI-Encode
Version     : 1.1.1
Release     : 21.cm2
Architecture: noarch
Install Date: Wed Sep  6 19:27:10 2023
Group       : Unspecified
Size        : 36127
License     : GPL+ or Artistic
Signature   : (none)
Source RPM  : perl-URI-Encode-1.1.1-21.cm2.src.rpm
Build Date  : Wed Sep  6 19:16:49 2023
Build Host  : redmon
URL         : https://metacpan.org/release/URI-Encode
Summary     : Percent encoding/decoding for URIs
Description :
This module provides a method to encode strings (mainly URLs) into a format
which can be pasted into a plain text emails, and that those links are
'click-able' by the person reading that email.  This can be accomplished by NOT
encoding the reserved characters.

This will satisfy your package dependencies.

Thanks for sharing https://github.com/elsaco/cbl-mariner-rpms/blob/main/perl-URI-Encode-1.1.1-21.cm2.noarch.rpm compiled package, @elsaco . it WORKS.

pramenku commented 1 year ago

Hi @elsaco Can you please help with https://github.com/microsoft/CBL-Mariner/issues/6308